• 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

Retaining value of checkbox when returning back from a servlet

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello,

I'm trying to retain the value of the checkbox when returning to the same servlet from another servlet. How can i implement it.

Scenario:

Servlet A has checkbox which post to servlet B then i want to go back to servlet A again and modify the checkbox that i selected before.


So how do i maintain the previously selected checkboxes [i want the checkbox to be checked when it reloads] ???

P.S. Hope my explanation is understandable.
 
Ranch Hand
Posts: 1179
Mac OS X Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How is you checkbox coded - just a normal HTML checkbox, or is it from some kind of framework (JSF, MyFaces, etc)??

If it is a normal checkbox, you can use javascript (written from the Servlet), and if it is from a framework, there should be a property to set on the returning object.
 
kan tao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got the idea of Httpsession but now my prob is the display part.

Here is some section of my code:

servelt A



servlet B




So when the submit button Back is press, How to retrive the session value in Servlet A and retain the checked value [display those checked boxes as checked]??
 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why do you need to print all this HTML tags from a Servlet? No JSP?
 
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
Just set the checked attribute onto the checkbox element that you wish to be checked.

And yeah, building up HTML inside strings inside a Servlet is a very poor practice.
 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should use the encodeRedirectURL() method in conjunction with sendRedirect() when redirecting to another part of your website. This must be done in order to property retain the session ID. From the JavaEE API:

All URLs sent to the HttpServletResponse.sendRedirect method should be run through this method. Otherwise, URL rewriting cannot be used with browsers which do not support cookies.

 
Michael Angstadt
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, please BeForthrightWhenCrossPostingToOtherSites. The same question was posted here.
 
kan tao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply everyone...


hi Michael Angstadt

Thanks for the reply. But i got another issue now ..

this code is suppose to save the session id and send to "servletA" where i can retrieve the session data through

But somehow its not working and returning NULL always. Can you point out where i'm doing it wrong??
 
Michael Angstadt
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you also post the code that sets the attribute? If the attribute name you're using to set the attribute doesn't match the name you're using to get the attribute, then it would make sense that it's returning null.
 
kan tao
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Servlet B



Servlet A



I have even try using forward but still its not working.

Below is the link where i was discussing the issue :

http://www.java-forums.org/java-servlet/30663-retaining-value-checkbox-when-returning-back-servlet.html
 
reply
    Bookmark Topic Watch Topic
  • New Topic