I created a simple login page. If the user entered right username and password the page ill be redirected to the success page otherwise it will be redirected to the index page. In login page i given the form submit action to the servlet. Once the servlet validates the input it will dispatched to the respective jsp page. My problem was the action name still in the url after the dispatch also. Is it right?
package com.123.www;
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;
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;
public Login() {
super();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("text/html");
//PrintWriter out = response.getWriter();
String userName = request.getParameter("username");
String passWord = request.getParameter("password");
RequestDispatcher view = null ;
if((userName=="")&&(passWord==""))
{
view = request.getRequestDispatcher("index.jsp");
}
else
{
HttpSession session = request.getSession(true);
session.setAttribute("name",userName);
view = request.getRequestDispatcher("success.jsp");
}
view.forward(request, response);
}
}