标签:
配置 servlet
1 <servlet> 2 <servlet-name>one</servlet-name> 3 <servlet-class>servletlearn.FirstServlet</servlet-class> 4 </servlet> 5 <servlet-mapping> 6 <servlet-name>one</servlet-name> 7 <url-pattern>/test</url-pattern> 8 <url-pattern>/test1</url-pattern> 9 </servlet-mapping> 10 11 <servlet> 12 <servlet-name>two</servlet-name> 13 <servlet-class>servletlearn.SecondServlet</servlet-class> 14 </servlet> 15 <servlet-mapping> 16 <servlet-name>two</servlet-name> 17 <url-pattern>/test2</url-pattern> 18 </servlet-mapping>
FirstServlet.java
package servletlearn; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class FirstServlet extends HttpServlet { protected void service(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException { System.out.println("我的第一个servlet程序运行啦!!"); } }
SecondServlet.java
package servletlearn; import java.io.IOException; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class SecondServlet extends HttpServlet { protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { System.out.println("我的第二个servlet!!!"); System.out.println("客户端浏览器类型:"+req.getHeader("User-Agent")); res.getWriter().println("<h1>Hello Servelet!!!</h1>"); res.getWriter().println("<h2>Hello Servelet!!!</h2>"); } }
标签:
原文地址:http://www.cnblogs.com/gpdm/p/5889261.html