Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

user registration via Servlet/JSP/JDBC  RSS feed

 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I have created a user registration JSP page accepting username, password & address. On Clicking submit flow navigates to the servlet.

Servlet code




Guys I want if the table update is successful, user is navigated to a new jsp page with this message " Welcome 'Username'". Please help me out, how do I do that ???
 
Jelle Klap
Bartender
Posts: 1952
7
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can either forward (internally) to the desired page using RequestDispatcher.forward(), or send a redirect response to the browser using HttpServletResponse.sendRedirect(). Using either of these (one more appropriate then the other) you can greet your user with a welcome message, and depending on the intent of the user, you can start restoring a backup of your database.
 
mallikarjun dontamsetti
Ranch Hand
Posts: 246
Firefox Browser Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ResultSet rs= stmt.executeQuery(queryString);

rs.next() will give you true if it inserts. based on this condition you can forward to any page you like as @Jelle Klap said.
and you can set a message in session attribute or in query string, and you can get that message in forwarded page. In your case set username in session or query string
eg:
 
shivang sarawagi
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Whenever I am using session.setAttribute(); do I always have to first create a session by

HttpSession session = request.getSession(); ???
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, that doesn't necessarily create a session, just obtains a reference to it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!