This week's book giveaway is in the Server-Side JavaScript and NodeJS forum.
We're giving away four copies of Micro Frontends in Action and have Michael Geers on-line!
See this thread for details.
Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

servlet error message to jsp

 
Greenhorn
Posts: 7
Netbeans IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,
I have a servlet that adds entries to a table and when there is a duplicate it redirects to an error page and I'd like to make it display the duplicate entry id.
The problem is when I try to get the parameter and show the error (the duplicate entry id) on my jsp error page it shows null instead of the appropriate number.

this is my servlet:



and the jsp:



What should I do?
 
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, stop using Java code n your JSPs. That's a bad practice from over 13 years ago. 13 years.

Second, you are doing a redirect, so all request info is lost. You'll either need to pass any info as parameters, or store in session.
 
Nassia Papasaras
Greenhorn
Posts: 7
Netbeans IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I stored it in session and now it works, so thanks for that.
I agree on not using java code in JSPs, however only when there's a lot of code that can be written let's say into a Servlet, small bits IMHO are acceptable.
 
Master Rancher
Posts: 4669
49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nassia Papasaras wrote:I stored it in session and now it works, so thanks for that.
I agree on not using java code in JSPs, however only when there's a lot of code that can be written let's say into a Servlet, small bits IMHO are acceptable.



Both bits of Java code in your JSP can be done using tags and el, which is what they are for. So no, you should have no Java code in your JSP.

Also, you should not be storing request stuff in your session if it's not needed between requests (which this is not likely to be).
Why are you not simply forwarding to the JSP pages?
Why do a redirect?
 
Bear Bibeault
Marshal
Posts: 67451
173
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Nassia Papasaras wrote:small bits IMHO are acceptable.


Sorry, but they are not. The small bits that you have are easily replaceable with JSTL and EL expressions. Using scriptlets in 2015 is not only a bad practice, it is irresponsible and amateurish.
 
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:
Why are you not simply forwarding to the JSP pages?
Why do a redirect?



The OP may be implementing the Post-Redirect-Get pattern. However, you could make an argument for forwarding in cases like this where an error prevents the state from actually changing.
 
Nassia Papasaras
Greenhorn
Posts: 7
Netbeans IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Dave Tolls wrote:
Both bits of Java code in your JSP can be done using tags and el, which is what they are for. So no, you should have no Java code in your JSP.

Also, you should not be storing request stuff in your session if it's not needed between requests (which this is not likely to be).
Why are you not simply forwarding to the JSP pages?
Why do a redirect?



Tbh I didn't know about tags, my java instructor taught my class to do it this way and that's what I've been doing.
I'll look into tags, thank you.
I know about forwarding, I use it in other pages I just couldn't get it to work for this one.

Bear Bibeault wrote:
Using scriptlets in 2015 is not only a bad practice, it is irresponsible and amateurish.


lol
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic