写了一个filter,错误就转向首页,但是地址栏仍然显示的是当前页的地址!!
解决方案 »
- java web小项目也不仅仅是数据库的增删改查!
- 关于javascript传参数带特殊符号报错的问题。。急,在线等!!!
- struts 问题
- struts2文件下载+动态设置文件名
- jsp在LINUX下tomcat4.13有时老是出现白屏现像,请问是什么原因,如何解决?
- 表达式语言不能运行,请问各位大侠是什么原因????
- 如何判断javascript
- 问一个简单的session问题!!谢谢各位了!!!!!!很着急!!!!
- 请问如何安装JBOSS3.0(包含Tomcat4.0)?
- IDEA中使用velocity模板的问题???
- 可逆加密和不可逆加密的区别
- 熟悉powerdesigner设计的大大进
不能改变地址栏的地址,但仍会转向xxx页面如果你用MVC模式
//将servlet请求转发给你要转向的页面
RequestDispatcher dispather=request.getRequestDispatcher("xxx");
dispather.forward(request,response);那么 不仅转向xxx页面而且地址栏的地址就会改变
FilterChain arg2) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;
HttpSession session = request.getSession();
String path = request.getServletPath();
if (!"/index.jsp".equals(path)) {
}
String user = (String) session.getAttribute(Constants.USERID);
if (user == null && !"/index.jsp".equals(path)) {
String errors = "请重新登录。";
request.setAttribute("errors", errors);
response.sendRedirect(request.getSession().getServletContext()
.getContextPath()
+ "/index.jsp");
} else {
arg2.doFilter(request, response);
}
}
你确定 localhost项目名/index.jsp能显示
因为看到sendRedirect相当于location.href,所以认为时可以的。结果还是不行!
筷子是用来喝汤,勺子是用来夹面的对吧。楼主,你这段多余的代码用来做什么的if (!"/index.jsp".equals(path)) {
}
显示两种方法都能显示的。首页没有做action映射(struts2),应为不想首页用filter。
我没记错的话,是服务器端跳转,地址栏不变,好久没耍SERVLET 的不知道是对是错
刚开始写的判断url来源的条件,属于多余还没有删除!不好意思!
使用request.getRequestDispatcher().forward(request,response)地址栏中保持不变
如果用了,那么对地址栏是没有影响的!
使用request.getRequestDispatcher().forward(request,response)地址栏中保持不变
使用request.getRequestDispatcher().forward(request,response)地址栏中保持不变