I need to logout from dahboard.jsp and go to index.jsp but while I'm clicking the logout button it is showing the error message like this,
HTTP Status 404 - /Project/logout
type Status report
message /Project/logout
description The requested resource (/Project/logout) is not available.
Apache Tomcat/6.0.20
the dashboard.jsp and the servlets login and logout are posted below, what might be the error in that.
dashboard.jsp
<div class="ends">
<form action="logout" method="post" >
<input type="submit" value="logout">
</form>
</div>
servlet page login 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");
}
}
Aucun commentaire:
Enregistrer un commentaire