Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

show text based on which page/jsp/servlet a user is coming from  RSS feed

 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am making a shopping cart app in JSP and servlets to bring it all together. Finally.

I have a registration servlet (c1), a registration form jsp (c2), a login jsp (c3). c1 checks if a username is in the database or not.
If the username is not there, then register the user and send them to c3. I want c3 to display a "registration successful" message if
a user has just registered successfully and is coming from c1. ELSE, take the user back to c2 with a message which tells them
to choose a different username or password etc.

How do I implement the logic of showing a message depending on where a user is coming from ? The servlets and jsps are
ready and I only need to add this logic for a custom message. Of course, I could make a JSP for Registration Successful and one for
Registration Failure. But, that seems to be unnecessary.

Please help me.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bad idea. Where the user is coming from is a spectacularly bad way to approach this.

The controller for the page should determine state from the information in the database, not something that's strongly bound or can be easily spoofed, like the previous page.
 
Paul Clapham
Sheriff
Posts: 22504
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ali Gordon wrote:Of course, I could make a JSP for Registration Successful and one for Registration Failure. But, that seems to be unnecessary.


Actually that seems like a good idea to me. What was your idea? One JSP for both, with conditional code which works based on whether registration was successful or not? If it were up to me I would go with the design with two JSPs.
 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Bad idea. Where the user is coming from is a spectacularly bad way to approach this.

The controller for the page should determine state from the information in the database, not something that's strongly bound or can be easily spoofed, like the previous page.


Can you please suggest how would I implement this logic ?

EDIT - I only want the message reg/success or failure to depend on where the user comes from. Of course, c1 will check the database for authentication.

Thanks.
 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Ali Gordon wrote:Of course, I could make a JSP for Registration Successful and one for Registration Failure. But, that seems to be unnecessary.


Actually that seems like a good idea to me. What was your idea? One JSP for both, with conditional code which works based on whether registration was successful or not? If it were up to me I would go with the design with two JSPs.

I was thinking of one JSP but was not sure if that was the correct way.
 
Ali Gordon
Ranch Hand
Posts: 182
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please let me explain with code. This is the doPost method of c1 or registration servlet -



Now RegistrationForm will look for a request attribute called registrationStatus and display its contents. If the customer could register, the are sent to the login.jsp. Again,
Login.jsp will show them the custom message. The servlet is always deciding if a user is registered/authenticated or not.

How does this sound ?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!