都需要注意什么呢?
是不是还要配置xml啊?
都不懂 大家别笑话我...
是不是还要配置xml啊?
都不懂 大家别笑话我...
解决方案 »
- 高分求教,ssh annotation 在DAO如何注入sessionFactory
- 关于XML中节点XPath查询的java.lang.NullPointerException错误
- myeclipse 怎么配置weblogic
- 一个关于db2存储jbpm表的问题,急!!!
- struts2 web.xml配置问题
- 大家帮我看个函数getHibernateCFGFile("/")是什么用法?
- 关于jspSmartUpload多文件下载的问题
- 北美ERP公司诚聘JAVA/WEB开发人才(J2EE/JSP等)
- 关于LinkedList的删除问题
- tomcat环境下javabean使用jndi问题
- 菜鸟在线等解决方案--其实很简单
- 各位,请帮忙修改一下,感谢~~
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 Simple extends HttpServlet { /**
* Constructor of the object.
*/
public Simple() {
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 occure
*/
public void init() throws ServletException {
// Put your code here
}}
//表示要使用一个Servlet
<servlet>
//在web.xml文件内部起作用的名字
<servlet-name>Simple</servlet-name>
//servlet程序所在包.类名称
<servlet-class>net.hialex.Servlet.SimpleServlet</servlet-class>
</servlet>
//servlet映射地址
<servlet-mapping>
//在web.xml文件内部起作用的名字,与上面的名字一致
<servlet-name>Simple</servlet-name>
//具体映射路径,前面必须要有一个/
<url-pattern>/demo</url-pattern>
</servlet-mapping>
你可以在myeclipse里面新建一个servlet看看代码是怎么样的
含视频教程
Servlet被服务器实例化后,容器运行其init方法,请求到达时运行其service方法,service方法自动派遣运行与请求对应的doXXX方法(doGet,doPost)等,当服务器决定将实例销毁的时候调用其destroy方法。