解决:将输出写进doget里面 读取时默认读取doget文件。跳转时才会需要写进dopost
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=gb2312");//引入中文符集2312
PrintWriter out = response.getWriter();
out.println("欢迎您来访问20211003");
out
.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}
2.在浏览器一栏不写完地址也能显示界面的方法
打开web.xml 在最下面找到此行代码,将页面更改为默认界面为My.jsp,此时在地址栏输入网址时为项目名即可打开
<welcome-file-list>
<!-- 所要设定的欢迎界面 -->
<welcome-file>My.jsp</welcome-file>
</welcome-file-list>
显示结果如图