• 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

forwarding to another page using a servlet

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Trying to validate form entries using a servlet and it's working fine. The problem is if a field wasn't filled out, I want to display it on another page. I have it printing what field wasn't filled in on tomcat but can't get it to display on another page using the forward method. I'm receiving null instead of the field that wasn't filled in. The error messages are stored in the class. The System.out.println you see here are for displaying in the tomcat window. Any ideas? Here's the code -


if (valresult.equals("val")) {

RecordValClass.getInstance().insertUsers(rv);
request.getRequestDispatcher ("jsp/successpage.jsp").forward
(request,response);

}else{

request.getRequestDispatcher("jsp/errorpage.jsp?valerror= " +
valresult.toString()).forward (request,response);

System.out.println("result after 15: " + valresult.toString());

}
[ December 14, 2004: Message edited by: Jim Shapt ]
 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Make sure you are you checking for request parameter valerror on your jsp page and not valresult
Also in the servlet, if valresult is a string with spaces, you should add URLEncoder.encode to it, before appending it to the URL errorpage.jsp
Thanks
Padma
 
Jim Shapt
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I've tried both valerror and valresult. The difference is if I put in valerror then nothing is there. If I put in valresult I get null.

URLEncoder.encode you mean put this in as an import? If so I have it import java.lang.Object.*;


Thanks
 
Padma Lalwani
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
valresult will be null as it is not a request parameter
when you say valerror is nothing, do you mean empty string or null or the value "null"? And what should the value of valerror be?

For URLEncoder you import java.net package & encode is static method
Then you say:
request.getRequestDispatcher("jsp/errorpage.jsp?valerror= " +
URLEncoder.encode(valresult)).forward (request,response);

Also just for testing out this valerror, you might want to try out redirect instead of forward to check the URL and the parameters on the address bar.
Thanks
Padma
 
Jim Shapt
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for replying.

When I said nothing I mean there is nothing on the page. Meaning null doesn't exist or anything else. Valerror should be the error messages that I�m trying to pull from a class (RecordValClass). This is where all the validating is taking place.

The import is done. For the other suggestion how would I use redirect in this method (sorry I'm a beginner you have to show me examples). The problem basically is, after all the troubleshooting I've done, it's not getting the error messages from the class and putting it on the error jsp page.

Thanks,

Jim
[ December 14, 2004: Message edited by: Jim Shapt ]
 
Jim Shapt
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well actually I just figured it out. Thanks for you help. For some reason
valerror is placed in both spots. Not sure why but it works. Thanks for you help.
 
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic