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 .
Method / Step
-
First, create a simple dynamic web project.
Open eclipse, click on the toolbar file File --New New --Project project
-
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.
-
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.
-
Javax.servlet.HttpServlet class extends inherit this class to inherit HttpServlet under javax.servlet.http
-
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.
-
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.
-
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
-