动态生成HTML文档

作者: 神坛下的我 | 来源:发表于2018-08-19 18:08 被阅读0次

    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

    相关文章

      网友评论

        本文标题:动态生成HTML文档

        本文链接:https://www.haomeiwen.com/subject/pxzciftx.html