编程开发 > JSP > 文章内容

jsp复习资料(23)

2017-1-22编辑:ljnbset
编写一个简单的Servlet
HelloServlet.java文件的代码,它实现了在浏览器中输出指定的信息。
1 package com.jsp.chap08;

3 import java.io.IOException;
4 import java.io.PrintWriter;

6 import javax.servlet.ServletException;
7 import javax.servlet.http.HttpServlet;
8 import javax.servlet.http.HttpServletRequest;
9 import javax.servlet.http.HttpServletResponse;
10 
11 public class HelloServlet extends HttpServlet {
12 
13     public void service(HttpServletRequest req,
14             HttpServletResponse res) throws IOException {
15         res.setContentType("text/html");
16         PrintWriter out = res.getWriter();
17         out.println("<html><head><title>Hello World!</title></head>");
18         out.println("<body>");
19         out.println("<h2><center>Hello World!</center></h2></body></html>");
20     }
21 }
jsp复习资料(20)

热点推荐

登录注册
触屏版电脑版网站地图