从仪表板注销会导致错误404:请求的资源不可用

时间:2017-04-27 08:00:19

标签: java jsp tomcat servlets web

我需要从dahboard.jsp注销并转到index.jsp,但是当我点击退出按钮时,它会显示如下错误消息,

  

HTTP状态404 - /项目/注销
  类型状态报告
  消息/项目/注销
  description请求的资源(/ Project / logout)不可用   Apache Tomcat / 6.0.20

dashboard.jsp和servlets登录和注销都发布在下面,可能是错误。

dashboard.jsp

<div class="ends">
    <form action="logout" method="post" >
        <input type="submit" value="logout">
    </form>
</div>

servlet页面登录login.java

package com.signin;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import com.db.DBCon;
/**
 * Servlet implementation class login
 */
public class login extends HttpServlet { 
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html");
        PrintWriter out = response.getWriter();

        String uid=request.getParameter("uid");
        String pwd=request.getParameter("pwd");


        try {
            DBCon dbc = new DBCon();
            if(dbc.validateLogin(uid, pwd))
            {
                HttpSession session=request.getSession();
                session.setAttribute("userid",uid);

                response.sendRedirect("dashboard.jsp");
            }
            else
                out.println("<center><h3>Sign in Failed!</h3><br><a href='index.jsp'>Go to Sign up page</a></center>");
            dbc.closeCon();
        }
        catch(Exception e){ e.printStackTrace(); }
    }
}

logout.java

package com.signin;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;   
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

/**
 * Servlet implementation class logout
 */
public class logout extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub

        HttpSession session=request.getSession();
        session.removeAttribute("userid");
        session.invalidate();
        response.sendRedirect("index.jsp"); 
    }

}

1 个答案:

答案 0 :(得分:1)

检查您的web.xml文件是否正确映射注销类。问题可能出在那里。否则,请分享完整的错误说明和网站。