0

我已经使用 servlet 和 JSP 创建了登录页面。它适用于首次登录。但是在注销后,如果我尝试另一个登录 servlet 会被执行,因为我可以在 url 中看到它,但看不到输出。

验证.java

package servlets;

import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class validate extends HttpServlet {

/**
 *
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */
public void doPost(HttpServletRequest request,HttpServletResponse 
 response) 
  throws ServletException,IOException
{
 response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
 try{
 String name=request.getParameter("email");
 String pass=request.getParameter("password");
 Class.forName("org.sqlite.JDBC");
 Connection con= DriverManager.getConnection("jdbc:sqlite:C:\\SQLITE\\ MYDATABASE.DB");
 Statement s=con.createStatement();
  ResultSet rs;
  rs = s.executeQuery("SELECT * FROM LOGIN WHERE EMAIL_ID='"+name+"' ");

  if(rs.next())
  {

 if( (name.trim().equals(rs.getString(3).trim())) && (   
   pass.trim().equals(rs.getString(6).trim()) )  )
{

 //New session creation
  HttpSession session=request.getSession(true);
  //setting attribute on session
  session.setAttribute("user",name);
 //send request to Welcome.jsp page

  RequestDispatcher view =request.getRequestDispatcher("welcome.jsp");

  view.forward(request, response);

}
else
 {
  out.println("<div style='font-size:30px; color:red'>" +"Userid and password does not          matched "+"</div>");
   RequestDispatcher view =request.getRequestDispatcher("login.html");

 view.include(request, response);
     }
  }
 else
  {
   out.println("<div style='font-size:30px; color:red'>"+"Please fill userid and password"+"</div>");
   RequestDispatcher view=request.getRequestDispatcher("login.html");
   view.include(request, response);
  }
    }catch(Exception e){}
 finally{
   out.close();
  }
  }
 }

注销.java

package servlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class logout extends HttpServlet {

/**
 *
 * @param request
 * @param response
 * @throws ServletException
 * @throws IOException
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {

response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
 try {
HttpSession session=request.getSession();
session.invalidate();
out.println("<div style='float:left;font-size:25px;'>"+"click here to "
   +"<a href='login.html'>login</a></div>");
out.println("<h1 align='center'>"+"Logout Sucessfully..."+"</h1>");
 }finally {            
 out.close();
 }
 }
 }
4

1 回答 1

0

也许“看不到输出”,因为有一个异常并且您在代码中忽略了它:

}catch(Exception e){}

尝试在 catch 块中添加一些日志,看看是否是这种情况。

于 2013-09-02T10:24:18.580 回答