jsp页面重定向后地址栏controller名重复而导致报404错误
今天做ssm项目时遇到了这种错误

看看代码:
无关代码省略。。。
22 <body>
23 <div id="container">
24 <iframe id="header" src="${pageContext.request.contextPath }/header.jsp" width="980" height="136" frameborder="0" scrolling="no"></iframe>
25 <div id="main">
26 <div class="cat">
27 <%
28 List<Category> pcategories = (List<Category>)session.getAttribute("pcategories");
29 if(pcategories==null){
30 response.sendRedirect("categoryController/getParentCategoryId");
31 return;
32 }
33 for(int i = 0 ; i < pcategories.size() ; i ++){
34 Category pcategory = pcategories.get(i);
35 %>
36 <ul>
37 <h1><%=pcategory.getName() %></h1>
38 <%
39 Set<Category> ccategories = pcategory.getcCategory();
40 for(Category child : ccategories){
41 %>
42 <li><a href='${pageContext.request.contextPath }/info.jsp'><%=child.getName() %></a></li>
43 <%
44 }
45 %>
46 </ul>
47 <%
48 }
49 %>
50 无关代码省略了。。。
68 <%
69 List<Product> products = (List<Product>)session.getAttribute("products");
70 if(products==null){
71 response.sendRedirect("productController/getImageById");
72 return;
73 }
74 for(int k = 0 ; k < products.size() ; k++){
75 Product product = products.get(k);
76 /* Iterator<ImageDTO> imagesIter = dto.getImagesDTO().iterator(); */
77 Set<Image> images = (Set<Image>) product.getImages();
78 for(Image image : images){
79 %>
80 <dl>
81 <dt>
82 <img src="${pageContext.request.contextPath }/upload/<%=image.getUrl() %>" alt="alt" width="90" height="90" />
83 </dt>
84 <dd>
85 <a href="${pageContext.request.contextPath }/infoController/getProductInfo?productIdStr=<%=image.getProductId() %>"><%=product.getName() %></a>
86 </dd>
87 </dl>
88 <%
89 }
90 %>
91 <%
92 }
93 %>
94
133 </body>
134 </html>
上面红色部分就是重定向的代码,跑上面代码就报404,百度了几个小时,没找出解决方案,后来自己仔细想一想,确定是重定向的路径错误。
于是一开始做了以下修改:
if(pcategories==null){
response.sendRedirect("${pageContext.request.contextPath }/categoryController/getParentCategoryId");
return;
}
无脑加上${pageContext.request.contextPath }(@_@原谅我的新手。。。)
发现还是报错。。。
又百度了一堆还是没解决,自己又再想想,思路没错,应该是写法出错,嗯,是这样!
果然,做了以下修改后就正确了
if(products==null){
response.sendRedirect(request.getContextPath()+"/productController/getImageById");
return;
}
jsp页面重定向后地址栏controller名重复而导致报404错误的更多相关文章
- Eclipse配置tomcat后,启动tomcat,访问tomcat报404错误
当你在Eclipse中新建一个工程,配置好tomcat,然后测试tomcat是否配置成功的时候,报404错误异常. 解决方法: 1,把工程文件删除,重新建立一个新的工程, 2,新建一个工程. 3,Ne ...
- JSP-Runoob:JSP 页面重定向
ylbtech-JSP-Runoob:JSP 页面重定向 1.返回顶部 1. JSP 页面重定向 当需要将文档移动到一个新的位置时,就需要使用JSP重定向了. 最简单的重定向方式就是使用respons ...
- springMVC配置时,静态资源和jsp文件路径没错但是访问时controller的请求报404错误。
springMVC配置时,静态资源和jsp文件路径没错但是访问时controller的请求报404错误. 1.场景 如果在web.xml中servlet-mapping的url-pattern设置的是 ...
- <mvc:default-servlet-handler/>导致controller失效,报404错误
最近在做ssm框架整合的一个小项目时,页面跳转一直有404错误,也没有报错提示.然后一步一步去找,终于发现是<mvc:default-servlet-handler/>的原因.如下图所示, ...
- 在ubuntu上面安装phpmyadmin后,报404错误
安装完mysql后,我想装一个phpmyadmin方便mysql管理. 在终端执行命令:sudo apt-get install libapache2-mod-auth-mysql phpmyadmi ...
- IntelliJ IDEA 文件夹重命名--解决重命名后js文件引用找不到路径报404错误
情景: 说明:ExtJS是我后来的改的名字--原来叫extjs,可是当我把在页面的引用地址改为 src="ExtJS/.."后页面就报404错误,我把它改回之前的extjs就可以( ...
- tomcat第一次使用正常启动后访问8080端口报404错误
问题:tomcat第一次使用正常启动后访问8080端口报404错误 解决办法:双击tomcat调出tomcat的xml文件页面,Server Locations 默认是选第一行即Use Workspa ...
- Vue项目build打包部署到Tomcat后,刷新报404错误解决方案
问题描述: 一.更新依赖,并打包项目 cd /root/.jenkins/workspace/v-test;npm installcd /root/.jenkins/workspace/v-test; ...
- 前端jsp页面script引入url项目名使用${appName}
<script src="/${appName}/commons/jslib/CommonValue.js"></script> 新建一个com.autum ...
随机推荐
- PHP单粒模式
<?php class C { //三私一公 protected static $_instance = null; protected function __construct() //pro ...
- 超全selenium元素定位XPath、CSS
说明:在HTML页面中,<p> 是一个标签,<p>hello</p> 是一个元素,元素由一个开始的标签和结束的标签组成.<font color="r ...
- Luogu1816 忠诚 (ST表)
继续复习模板,加深理解ing... #include <iostream> #include <cstdio> #include <cstring> #includ ...
- 解决使用 Eruda 绑定 dom 未在指定位置显示问题
前言 开发项目中,使用到 Eruda 打印控制台信息显示 文档:https://github.com/liriliri/eruda 安装 Eruda npm install eruda --save ...
- 快速创建springboot项目,并进行增删改
创建普通maven项目,pom依赖如下 <parent> <artifactId>spring-boot-starter-parent</artifactId> & ...
- suse 11 sp3编译报错问题
suse安装,默认是不安装gcc的,今天安装gcc之后,编译suse11 sp3,报错如下: scripts/basic/fixdep.c:106:23: fatal error: sys/types ...
- ByteBuffer数据结构
- 2022CISCN-satool
2022CISCN-satool 打国赛的时候自己还并不了解LLVM PASS pwn,前几天正好学习了一下LLVM PASS pwn,于是就顺便来复现一下这道题目. 首先找到二进制文件的重写函数的主 ...
- axios请求响应拦截器的应用
什么是axios拦截器? 一般在使用axios时,会用到拦截器的功能,一般分为两种:请求拦截器.响应拦截器. 请求拦截器在请求发送前进行必要操作处理 例如添加统一cookie.请求体加验证.设置请求头 ...
- 刷题记录:Codeforces Round #731 (Div. 3)
Codeforces Round #731 (Div. 3) 20210803.网址:https://codeforces.com/contest/1547. 感觉这次犯的低级错误有亿点多-- A 一 ...