我的第一个servlet文件 欢迎光临无法正常显示

解决:将输出写进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>

显示结果如图在这里插入图片描述

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值