将war包部署到服务器tomcat时候遇到问题

YourMart 2019-11-13 05:04:41
将war包部署到服务器tomcat时候遇到问题
首页正常进入,但是一旦我点击JSP页面的BUTTON请求servlet时候就会出现404,访问的资源未公开



war包解压后的结构本来就是classes在WEB-INF下面嘛
我要怎么才能使页面发生请求时能成功进入servlet呢?
...全文
223 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
YourMart 2019-11-14
  • 打赏
  • 举报
回复
引用 6 楼 叶遮沉阳 的回复:
${pageContext.request.contextPath}失效的原因可能有两种:

1. jsp默认<%@ page isELIgnored="true"%>,只要在有EL表达式的jsp页面限制<%@ page isELIgnored="false"%>。 就可以正确解释EL表达式了。

2. 说是web.xml 里面的web-app元素声明的版本号太低,即2.4以上才能用。

建议换种方式:

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

使用 <%=basePath %> 替代 ${pageContext.request.contextPath}







谢谢6楼大佬帮忙,完美解决!牛逼!
叶遮沉阳 2019-11-14
  • 打赏
  • 举报
回复
${pageContext.request.contextPath}失效的原因可能有两种: 1. jsp默认<%@ page isELIgnored="true"%>,只要在有EL表达式的jsp页面限制<%@ page isELIgnored="false"%>。 就可以正确解释EL表达式了。 2. 说是web.xml 里面的web-app元素声明的版本号太低,即2.4以上才能用。 建议换种方式:

<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
使用 <%=basePath %> 替代 ${pageContext.request.contextPath}
YourMart 2019-11-13
  • 打赏
  • 举报
回复
<form id="formId" action="${pageContext.request.contextPath}/PatrolResult" method="post"> <%-- <input type="hidden" name="method" value="delCheck">--%> <c:forEach items="${list}" var="pr"> <tr> <td>${pr.line_name}</td> <td>${pr.plan_date}</td> <td>${pr.point_name}</td> <td>${pr.user_name}</td> <td>${pr.access_time}</td> <td>${(pr.result_flag)==1?"正常":"未巡"}</td> </tr> </c:forEach> 我有加啊。。。
IT_熊 2019-11-13
  • 打赏
  • 举报
回复
一般都是contextPath的问题
HelloWorld_AA 2019-11-13
  • 打赏
  • 举报
回复
错误的log日志****
maradona1984 2019-11-13
  • 打赏
  • 举报
回复
一般都是contextPath的问题,看样子是页面上没加contextPath
YourMart 2019-11-13
  • 打赏
  • 举报
回复
web.xml如下(备注:本地IDEA启动TOMCAT后一切正常,打成war包放服务器后发现发起请求时候会报404,是无法找到servlet导致)

<servlet>
<servlet-name>PatrolResult</servlet-name>
<servlet-class>servlet.PatrolResultServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PatrolResult</servlet-name>
<url-pattern>/PatrolResult</url-pattern>
</servlet-mapping>

<servlet>
<servlet-name>PatrolResultSecond</servlet-name>
<servlet-class>servlet.PatrolResultServletSecond</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>PatrolResultSecond</servlet-name>
<url-pattern>/PatrolResultSecond</url-pattern>
</servlet-mapping>


就这两个虚拟路径,而且没有设置任何过滤器和拦截器

67,514

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧