`
斌强-朱
  • 浏览: 51470 次
社区版块
存档分类
最新评论

Servlet

 
阅读更多



public class HelloWorld extends HttpServlet {
	
	@Override
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		resp.setContentType("text/html");
		PrintWriter out = resp.getWriter();
		out.println("<html><head><title>Hello</title></head><body>");
		out.println("<h1>This is H1</h1>");
		out.println("</body></html>");
	}
	
	@Override
	public void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}


<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
 <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
 </welcome-file-list>
 <login-config>
  <auth-method>BASIC</auth-method>
 </login-config>
 <servlet>
 	<servlet-name>hello</servlet-name>
 	<servlet-class>org.zbq.servlet.HelloWorld</servlet-class>
 </servlet>
 <servlet-mapping>
 	<servlet-name>hello</servlet-name>
 	<url-pattern>/hello</url-pattern>
 </servlet-mapping>
</web-app>







分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics