• 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

servlet error message to jsp

 
Greenhorn
Posts: 7
Netbeans IDE MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 4801
50
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic