How to use eclipse to create a simple servlet

Servlet is a java-based server program development, service can be announced, if a browser application, you can open the URL through the browser-view service. Create a servlet to inherit httpservlet, and is configured to intercept way in web.xml ,, Xiao Bian introduce how to create a simple servlet program in the Eclipse .

Tools / materials

 
  • development tools eclipse
  • httpServlelt包
  • java development environment

Method / Step

 
  1.  

    First, create a simple dynamic web project.

    Open eclipse, click on the toolbar file File --New New --Project project

    How to use eclipse to create a simple servlet
  2.  

    Select the dynamic web project . In the pop-up project type, select a dynamic web project dynamic web project, the project name enter a project name input box, usually English.

    How to use eclipse to create a simple servlet
  3.  

    Create a java package and java File. In the src directory java package to create a new e-mail, create a java class in the package.

    How to use eclipse to create a simple servlet
  4.  

    Javax.servlet.HttpServlet class extends inherit this class to inherit HttpServlet under javax.servlet.http

    How to use eclipse to create a simple servlet
  5.  

    Rewrite doGet and doPost methods. Ankuaijiejian alt + / rewrite and doPost doGet method, the general call directly doGet doPost method. Output word inside doPost method, this method detects whether enter inside.

    How to use eclipse to create a simple servlet
  6.  

    Create a servlet interceptors in web.xml.

    The main is to configure the servlet and servlet-mapping.

    Note that two servletname to remain the same.

    How to use eclipse to create a simple servlet
  7.  

    Deployment projects run the project. Deploy the project to the tomcat, Run, type in the browser address format is ip + port + Project Name + interceptor address

    How to use eclipse to create a simple servlet
  8.  

Guess you like

Origin www.cnblogs.com/guohu/p/11504104.html