RequestDispatcher to a jsp or servlet

243 views Asked by At

Parameters[userName, UserPW] are sent by the user through a home.jsp. These parameters are matched in Login servlet against a stored userInfo Db using JDBC.

In the doPost method I am using if condition tfor authentication as follows

if (rs.next()) {
            String refName = rs.getString("UserName");

            String refPass = rs.getString("userPW");

            if (user.equals(refName) && pw.equals(refPass)) {

                out.println("<br>You are In");

                RequestDispatcher dispatch= getRequestDispatcher("/SearchFriend.jsp");
                dispatch.forward(req, resp);

                System.out.println("sucess");

            }

When the authentication is successfull, How can i direct the user to a new jsp or servlet where he can input few textboxes and select-options to select few records from the Db table. its not clear to me that How can I direct the page to a Search.jsp page in above If condition. The Search.jsp is in weBContent folder of Juno.

I am using JDBC with tomcat7. Please help

1

There are 1 answers

0
Manish Sahni On

It is probably not clear , what exactly your requirement are and what you are trying to achieve by looking into the code you have posted.Kindly reframe your question

According to my assumption , you need to redirect the user to the home page when the authentication is successful.

If so, for that you can store the user credential in the session by making a custom filter say SessionFilter implements Filter

HttpSession session = request.getSession();

Store the credenials in the session and if authentication is successful then redirect using :

RequestDispatcher view = request.getRequestDispatcher(/home.jsp);
view.forward(req,resp);