UseServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class UseServlet extends HttpServlet{
private static final long serialVersionUID = 1L;
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
//设置字符集格式为utf-8
resp.setCharacterEncoding("UTF-8");
//设置响应正文的MIME类型
resp.setContentType("text/html");
PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head><title>动态生成HTML文档</title></head>");
out.println("<body>");
out.println("<table border='0' align='center'>");
out.println("<tr><td bgcolor='skyblue' colspan=2>动态生成HTML文档</td></tr>");
out.println("</table>");
out.println("</body");
out.println("</html>");
out.flush();
out.close();
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
doPost(req, resp);
}
}
web.xml
<servlet>
<servlet-name>UseServlet</servlet-name>
<servlet-class>com.use.UseServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UseServlet</servlet-name>
<url-pattern>/html</url-pattern>
</servlet-mapping>
11.PNG
网友评论