1
자바로 시작하고 로그인을 구현하는 데 어려움이 있습니다. 역할 (DB에 등록 된)에 따라 내 서블릿이 사용자를 다른 방향으로 리디렉션합니다. 많은 다른 버전을 시도했으며 마지막 시도를 수행합니다. 나는 왜 작동하지 않는지 이해할 수 없다. (사용자가 페이지에 서블릿 리다이렉트로 admin으로 로그인하면) 다른 오류 (논리적 인 경우)가있는 경우 말해주십시오. 나는 향상시키고 싶다. 답변 해 주셔서 감사합니다.역할이있는 java 서블릿 로그인
내 DAO :
public String esisteAccount (Account a) {
Account acc = new Account();
String query = "SELECT * FROM account WHERE username = '?' and password='?'";
query=query.replaceFirst("[?]", (a.getUsername()));
query=query.replaceFirst("[?]",(a.getPassword()));
Vector<Object> v =db.executeSelect(query, "Account");
acc = (Account)v.get(0);
String ruolo;
if (v.size()>0){
ruolo=acc.getRuolo();
}
else {
ruolo="nonAutorizzato";
}
return ruolo;}
내 dbManager
if (type.equals("Account"))
{
Account a;
a = new Account();
a.setUsername(rs.getString("username"));
a.setPassword(rs.getString("password"));
a.setRuolo(rs.getString("ruolo"));
v.add(a);
}
과는 prblem가 여기에
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username=request.getParameter("username");
String password=request.getParameter("password");
Account a = new Account();
a.setUsername (username);
a.setPassword (password);
AccountDAO accountDAO =new AccountDAO();
String esito= accountDAO.esisteAccount(a);
if (esito=="nonAutorizzato"){
request.getRequestDispatcher("../errore.jsp").forward(request, response);
}
else {
HttpSession session=request.getSession();
if (esito=="Admin"){
session.setAttribute("autorizzatoAdmin","true");
request.getRequestDispatcher("autorizzatoAdmin.jsp").forward(request, response);
}
else{
session.setAttribute("autorizzato","true");
request.getRequestDispatcher("indexPL.jsp").forward(request, response);
}
}
문자열 비교에서 == 대신 .equals 메서드를 사용하십시오. –