0

I'm developping a little website for school with JSP and servlets, but i'm having a problem. I'm trying to restrict the access to the toolbox page, so only someone with the admin password could access to it.

So i put a little form (with post method) to get the password, and in my servlet i get it and check if it's the good one. But it seems like it always consider it's a wrong password and always redirect me to the wrong page ...

Content of my FiltreAdmin servlet :

public class FiltreAdmin extends HttpServlet {
public static final String VUE = "/WEB-INF/filtreAdmin.jsp";
public static final String ACCES_PUBLIC     = "/restreintAdmin.jsp";
public static final String ACCES_RESTREINT  = "/WEB-INF/toolbox.jsp";


public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
    this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );
}

public void doPost( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
    if ( request.getAttribute("passwd") != "freebeer" ) {
        /* Redirection vers la page publique */
        response.sendRedirect( request.getContextPath() + ACCES_PUBLIC );
    } else {
        /* Affichage de la page restreinte */
        this.getServletContext().getRequestDispatcher( ACCES_RESTREINT ).forward( request, response );
    }
}

}

Would someone have an idea ?

Gloumy
  • 63
  • 1
  • 6
  • You should read this: http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java – home Jan 18 '14 at 16:40

1 Answers1

0

Forgot to edit to post the answer .. My bad !

I found the solution thanks to the link of home (How do I compare strings in Java?)

I just needed to change my == and use the .equals() function instead.

Community
  • 1
  • 1
Gloumy
  • 63
  • 1
  • 6