web JSP filter 控制权限配置后,出现404错误

index.jsp登陆页面 UserServlet.java是针对登陆的一个servlet
UserFilter.java是控制权限的类show.jsp是登陆成功后进入的页面
error.jsp是当用户绕过index.jsp登陆直接通过控制url进入show.jsp时会跳出的页面。
图片说明
图片说明
图片说明

文件结构 XML配置 index.jsp如图

UserServlet.java
public class UserServlet extends HttpServlet{
public void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException,IOException{
String name=req.getParameter("username");
String password=req.getParameter("password");
UserInfo info= new UserInfo();
try{
if(password.equals("123456")){
info.setName(name);
info.setPassword(password);
req.getSession().setAttribute("userinfo", info);
System.out.println("登陆成功");}
else{
System.out.println("登录失败");}}
catch(Exception e){
e.printStackTrace();}
RequestDispatcher rd=req.getRequestDispatcher("/show.jsp");
rd.forward(req, resp);}
public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException{
doGet(request,response);}}
UserFilter.java
public class UserFilter {
public void destroy() {}
public void doFilter(ServletRequest request, ServletResponse response,FilterChain filter) throws IOException, ServletException {
UserInfo info=(UserInfo)((HttpServletRequest) request).getSession().getAttribute("userinfo");
if(info.getName()!=null) {
filter.doFilter(request, response); }
else {
response.setContentType("text/html;charset=utf-8");
((HttpServletResponse) response).sendRedirect("../error.jsp"); }}
public void init(FilterConfig arg0) throws ServletException {}}

404,是你点击哪个页面出来的呢,还是说一访问login.jsp登陆用户名时候跳转404?,如果是这样的话,

http://blog.csdn.net/liuxiaogangqq/article/details/8257400
参考一下这个,你的过滤器代码中

if(info.getName()!=null) {
filter.doFilter(request, response);
}
如果用户存在,应该跳转,你为啥没跳转呢

一般是这样写

if (user != null) {

chain.doFilter(req, resp);

return;

}

        最后一堆判断,都符合了再跳转,而且你的error.jsp不是和show。jsp同级目录吗,为啥有..呢

为什么两个jsp你在servlet里写的路径不一样呢

404错误肯定不是权限问题,路径问题

应该是form action ="login"这里出问题了,相对路径没设置好
<%

String path = request.getContextPath();

String basePath = request.getScheme() + "://"

+ request.getServerName() + ":" + request.getServerPort()

+ path + "/";

%>

然后



用户上传图片页面



在《head》里头加上

图片说明