File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes problem when visiting same page again Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "problem when visiting same page again" Watch "problem when visiting same page again" New topic
Author

problem when visiting same page again

Ja vardhan
Ranch Hand

Joined: May 09, 2005
Posts: 169
Hi,
Ia displaying one jsp which is accessing some parametres (was setting in request attribute) like HashMap.Assume this page is having 10 check boxes, user clicks on 5 check boxes and will click on submit. Now after clicking on submit button in this page, the control will move to some action class to process some operation but user should be viewing that same page (the checkboxes status should remain same as he selected).
I am passing control to action class and processing some operation and then trying to revisit the page, but its showing NullPointerException since it needs some parameters (there is request.getParameter() method).
Whats the solution to this problem.
Pls reply ur valuble suggestions.
Thanks.


Javardhan:
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
You mean accessing attributes (i.e. request.getAttribute("myHashMap")), not parameters, right? You can't have a HashMap in a request parameter.

A few possibilities:

1. Put the attributes in the session instead of the request.

2. When submitting the form, don't change the current page - either make the target a new window, or a frame (possibly a hidden iframe.) That way the current page will keep displaying the checkboxes as checked. You can also do the submit using AJAX/XMLHttpRequest - search the HTML/Javascript forum for more info.

-Yuriy
Ja vardhan
Ranch Hand

Joined: May 09, 2005
Posts: 169
Hi Yuriy,

Thanks for your reply. I understood ur first point, but we are not supposed to maintain sessions according to application requirement.
Pls tell me the alternate way.
I didnt understood ur second point, pls tell me clearly.
Thanks once again.
Yuriy Zilbergleyt
Ranch Hand

Joined: Dec 13, 2004
Posts: 429
The second point deals more with HTML/Javascript than with Java, so maybe a moderator should move this topic to that forum.

You say that you don't want the page viewed by the user to change - do you mean you just want the submit to happen, but the user will not see anything change at all on the page, aside from maybe a "Submission successful" type message?

In this case you could use a hidden iframe:



Note that if there's a problem on the server side (even if test.jsp is not found) you'll still get the alert that the form was submitted. If that's not desirable, you can have the iframe's onload call a function that check's its contents.

A cleaner way would be to do this using AJAX, though it will fail on IE if users have disabled all ActiveX controls. For more info on AJAX, check the HTML/Javascript forum on this site - there are always tons of topics on this technology.

-Yuriy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem when visiting same page again