第一个Web项目
来源:互联网 发布:snmpwalk 端口号 编辑:程序博客网 时间:2024/05/10 15:25
步骤:
1)创建一个Web Project 。
2)创建一个Servlet。
3)配置web.xml文件。
4)测试。
----------------------------------
1)创建JqueryPulgin工程。
2)创建Servlet:
package org.ws.test;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ServletTest extends HttpServlet {
/**
* Constructor of the object.
*/
public ServletTest() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC /"-//W3C//DTD HTML 4.01 Transitional//EN/">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC /"-//W3C//DTD HTML 4.01 Transitional//EN/">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
3)web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>ServletTest</servlet-name>
<servlet-class>org.ws.test.ServletTest</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServletTest</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
4)测试url:
http://192.168.0.144:8080/JQueryPulgin/ServletTest
- 第一个Web项目
- 第一个web项目
- 第一个Java Web项目
- 第一个Java web项目
- java web第一个项目
- 第一个Java Web项目
- 第一个maven web项目
- java web第一个项目学习笔记
- django+python创建第一个web项目
- 用Maven创建第一个web项目
- 【读书札记】建立第一个Web项目
- 手动开发第一个Web项目
- 用Maven创建第一个web项目
- 用Maven创建第一个web项目
- 用Maven创建第一个web项目
- 用Maven创建第一个web项目
- 用Maven创建第一个web项目
- 用Maven创建第一个web项目
- 判断字符串中是否含有汉字及其汉字的个数
- nobody wait for you
- KVM还有加电顺序一说?
- Java Web 服务: WS-Security 的大开销
- 第三天:听课笔记
- 第一个Web项目
- 第三天:总结
- php页面间传值
- 第四天:听课笔记
- 第四天:总结
- Web rise in China
- 下拉菜單
- 关于一个oracle的问题?有急用,?
- 云安全 0升级 之360 度