form表单提交请求时的路径问题

本文探讨了解决JSP表单提交时遇到的404错误问题,通过调整web.xml配置和使用正确的路径引用,确保数据可以正确提交到目标Servlet。介绍了相对路径与绝对路径的使用方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题:jsp form表单提交数据时出现404错误访问不到目标源,如下图所示
404解决过程:

  1. 尝试用相对路径方法解决,但是未成功,如下
    		<label >user</label>
    		<input type="text" name="adminName"/>
    		<label >passwordš</label>
    		<input type="password" name="adminPassword">
    		<input type="submit" value="GO"/>•
    	</form>
    
  2. 将jsp文件写在了web.xml中使其成为默认的的初始页面。结果是访问成功,并且jsp中用的是相对路径,如下:
 <welcome-file>/readBook/html/login.jsp</welcome-file>
 		<form action="login/isLogin" method="post">
     		<label >user</label>
 			<input type="text" name="adminName"/>
     		<label >passwordš</label>
     		<input type="password" name="adminPassword">
     		<input type="submit" value="GO"/>•
     	</form>
  1. 绝对路径。将jsp文件的相对路径写在web.xml中固然能解决问题但是这不是我想要的结果,不是每个要求都是默认的起始页面
    1)
      <form action="/项目名/servlet/RegisterLoginServlet  " method=post>      	...</form>           	
其实绝对路径还有第二种方法:
<formaction="<%=request.getContextPath()%>/servlet/RegisterLoginServlet  " method=post>...</form>

参考.

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值