1

This is my Login.jsp page

<form name="login" action="ValidateServlet" method="post">  
<input type="hidden" name="pagename" value="login"/>   
<table>  

<tr>  
<td><b>USERNAME:</b><input type="text" name="txtUsername"/> </td>  
</tr>  

<tr>  
<td><b>PASSWORD:</b><input type="password" name="txtPassword"/></td>  
</tr>  

<tr>  
<td><input type="SUBMIT" value="SIGN IN"/></td>  
</tr>  

<tr>  
<td><a href= "/PasswordServlet">Forgot Password</a></td>  
</tr>  
<tr>  
<td><a href= "/SignUp"> Create New user </a></td>  
</tr>  
</table>  
</form>` 

And this is my SignupServlet:

protected void doPost(HttpServletRequest request, HttpServletResponse response throws          
 ServletException, IOException {  
 RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/WebPages/Signup.jsp");  
 rd.forward(request, response);  
}  

}

and this is my web.xml

<servlet>  
    <servlet-name>SignupServlet</servlet-name>  
    <servlet-class>com.affiliate.servlet.SignupServlet</servlet-class>  
</servlet>  

<servlet-mapping>  
    <servlet-name>SignupServlet</servlet-name>  
    <url-pattern>/SignUp</url-pattern>  
</servlet-mapping>  

Login.jsp is in Webcontent/WEB-INF/WebPages/Login.jsp and SignupServlet in JavaResources/src/com.affiliate.servlet/SignupServlet but my Login is not redirecting to the SignupServlet. And i have doubt on my href and form action. Please help me in this regard.

Wanna Coffee
  • 2,742
  • 7
  • 40
  • 66
user3222718
  • 242
  • 1
  • 7
  • 27
  • Maybe just a typo, but you consistently refer to the jsp as `Login.jsp` but the servlet refers to `Signup.jsp` - please recheck the names of all the involved components. Also, as you map the servlet to `/SignUp` why `
    ` ?
    – fvu Jan 22 '14 at 10:06
  • remove web-inf `protected void doPost(HttpServletRequest request, HttpServletResponse response throws ServletException, IOException { RequestDispatcher rd = request.getRequestDispatcher("/WebPages/Signup.jsp"); rd.forward(request, response); }` – Santino 'Sonny' Corleone Jan 22 '14 at 10:14

4 Answers4

0

Change this code

 protected void doPost(HttpServletRequest request, HttpServletResponse response throws          
 ServletException, IOException {  
 RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/WebPages/Signup.jsp");  
 rd.forward(request, response);  
} 

to

protected void doPost(HttpServletRequest request, HttpServletResponse response throws          
 ServletException, IOException {  
getServletContext().getRequestDispatcher("WEB-INF/WebPages/Signup.jsp").forward(request, response);
}  
Santino 'Sonny' Corleone
  • 1,735
  • 5
  • 25
  • 52
  • @fvu my login page is a form which on providing username and password will redirect to validateServlet for further processing. and same in the Login form i have two hrefs one is if the user has forgotten his/her password will click on forgotPassword which will direct him to some servlet. and on pressing create new user it will redirect to SignupServlet and SignupServlet has a dispatcher to redirect to Signup.jsp. Both Login.jsp and Signup.jsp are in WEB-INF/WebPages directory but i have a servlet to redirect it from login.jsp to Signup.jsp for security purpose – user3222718 Jan 22 '14 at 10:27
  • Thank u all i got it by changing `protected void doPost(HttpServletRequest request, HttpServletResponse response throws ServletException, IOException { getServletContext().getRequestDispatcher("/WebPages/Signup.jsp").forward(request, response); } `to `protected void doPost(HttpServletRequest request, HttpServletResponse response throws ServletException, IOException { getServletContext().getRequestDispatcher("WEB-INF/WebPages/Signup.jsp").forward(request, response); } ` – user3222718 Jan 22 '14 at 10:40
  • looks lyk I was the closest except for the web-inf – Santino 'Sonny' Corleone Jan 22 '14 at 10:47
  • oh sorry i didnt get how to write a code in this forum in comment am a newbie sorry all and thank you very much and thank you @Aniket for informing me about doGet() method in href it worked... – user3222718 Jan 22 '14 at 10:47
  • You will need to close this question since its answered..by giving a tick to the right one – Santino 'Sonny' Corleone Jan 22 '14 at 10:49
  • oh my i cant tick 2 so i give my vote to Aniket and @user3040563.... Thank you both for your valid answers... Bye – user3222718 Jan 22 '14 at 10:53
0

Change

<a href= "/SignUp"> Create New user </a>
          ↑

To

<a href= "SignUp"> Create New user </a>  

And in anchor tag there is no post method available. You need to change the code in SignupServlet

protected void doGet(HttpServletRequest request, HttpServletResponse response throws          
  ServletException, IOException 
{  
   RequestDispatcher rd = request.getRequestDispatcher("Signup.jsp");  
   rd.forward(request, response);  
}  

If you want post request using a tag then refer POST from an tag

Community
  • 1
  • 1
Aniket Kulkarni
  • 12,825
  • 9
  • 67
  • 90
  • this is the error am getting on changing my code as u said type Status report message /Affiliate/WebPages/Signup.jsp description The requested resource is not available. – user3222718 Jan 22 '14 at 10:34
  • @user3222718 : That means it is redirecting now, and just not able to find the Signup.jsp file. See my updated post. – Aniket Kulkarni Jan 22 '14 at 10:39
0
replace

<a href= "/PasswordServlet">Forgot Password</a> 
<a href= "/SignUp"> Create New user </a>

To

<a href= "PasswordServlet">Forgot Password</a> 
<a href= "SignUp"> Create New user </a>

Remove "/" before Servlet URL Pattern
Tusar
  • 759
  • 5
  • 21
0

In your login.jsp call SignUp servlet in following way

<td><a href= "SignUp"> Create New user </a></td> 

and In SignUp servlet in your doGet method

RequestDispatcher rd = request.getRequestDispatcher("/WEB-INF/webpages/Signup.jsp");  
         rd.forward(request, response); 

Because when you call a servlet from a link or href it the doGet method gets run. Hope this helps

Mudit Shukla
  • 814
  • 2
  • 6
  • 16