日期:2014-05-17  浏览次数:20682 次

servlet显示问题?
新人学习JSP和SERVELT



    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;


    public class HelloWorldSerlet extends HttpServlet{

        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
                throws ServletExceptionIOException {
            PrintWriter out = resp.getWriter();
            String str = "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">";
            out.print(str + "<HTML><head><title>example</title></head><body>Hello World Test!!!</body><HTML>");
        }
    }



怎么显示不对啊??

------解决方案--------------------
  response.setContentType("text/html");
或者
  setContentType("text/html;charset=GB2312");
请参看servlet html头信息