• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 182
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Hibernate Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic