• Post Reply Bookmark Topic Watch Topic
  • New Topic

Login Code Help

 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all I'm new Java Web Development & I want to write a code in which when a user logs in he should automatically get redirected to the home page. I have got this


its not working. Please help Many Thanks!
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you expect this code to do? You check two parameters and then print out part of a static HTML page, which has no dynamic at all to it...how should that page redirect the user somewhere else??

I assume this code is part of a servlet? If so, then you should check the methods getRequestDispatcher(..).forward(..) from the request object, or sendRedirect(..) from the response object.
 
Pranit Sonawane
Ranch Hand
Posts: 172
Java MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
D. Ogranos wrote:What do you expect this code to do? You check two parameters and then print out part of a static HTML page, which has no dynamic at all to it...how should that page redirect the user somewhere else??

I assume this code is part of a servlet? If so, then you should check the methods getRequestDispatcher(..).forward(..) from the request object, or sendRedirect(..) from the response object.

Oops! am sorry i forgot one line here. The actual code is

Sorry for the previous mistake
This is the actual code! and you guessed it right sir its a servlet code.
out.println("<form action="+response.sendRedirect("home.jsp")+ "method = 'post'>");
This line give me an error saying 'void' type is not allowed. What can i Do?
Please help.
Thanks!
 
D. Ogranos
Ranch Hand
Posts: 214
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the API for HttpServletResponse. You'll see that sendRedirect() does not return anything so of course you cannot add it in a String. You will also see that no other output is legal after a sendRedirect().

In other words: your servlet should not create any output (no println()). After checking the login parameters, your servlet can immediately call the sendRedirect() method with the URL of the success page (main menu or whatever).
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!