wood burning stoves 2.0*
The moose likes JSP and the fly likes Need to save a response , before sending it th the client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Need to save a response , before sending it th the client" Watch "Need to save a response , before sending it th the client" New topic
Author

Need to save a response , before sending it th the client

Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
BackGround :
The application has a WebPage [ customizePage.jsp ] , which allows users to specify some customizations . [ specify the number of textBoxes , values in dropDown etc . ] .

This webPage then makes a call to a servlet , which creates these elements at runtime .

So say like the user specifies , 5 textBoxes at runtime . So this number 5 is passed to the servlet in form of a Parameter .
Then in the java code , within a loop , five new textboxes would be created

These would be set in five different attributes , as Strings

The request and response are then sent to a jsp [ createdPage.jsp ] , using "Request Dispatcher" .

At runtime this code works fine and , fixe new TextBoxes are visible on the browser , using JSP expressions / scriptlets


Problem / Question :
Once the page is created . I want it to be saved . as in next time , instead of going through the entire process , one could simply access "createdPage.jsp" and it would show the final page . [ complete with 5 text boxes ] .
I am not sure how would i save the response .
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60072
    
  65

Why?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
hmmm... nice ques!!! :)

Anyways i guess , the idea is to allow one user to set up a page and then allow all others to simply use that page . Something that the template kind of websites allow you to do .

So i save the response once and then publish a link for it , which can then be used by others .

I was working on it and realized that i could simply save the request [ final request for the createdPage ] . So next time someone requests this published link , we replace the incoming request by the saved request , and send it in the RequestDispatcher object , which then shows up the setUp page .
Pete Nelson
Ranch Hand

Joined: Aug 30, 2010
Posts: 147

Rather than save the request, why not create a bean (or POJO) to store the submitted data? Then you could serialize it to the filesystem on the server for later use, as you suggest.


OCPJP
In preparing for battle I have always found that plans are useless, but planning is indispensable. -- Dwight D. Eisenhower
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
hmmm.. lets see.. Creating a POJO or a bean . But then i don't know which are the attributes or how many of them . So then there would be only a TreeMap , with the attribute Names as keys and the elements generated as values .
Managing that would obviosuly be a bit easier , than the present way of writing the individual ones in a text File . :(

However saving the request is also something that i am yet to achieve . Should i get an "InputStream" from the request and then reading the bytes write the entire request to a text file .
But then how do i replace the request back ??

I am working on these .

At present i am trying to dynamically add a "function : actually an onChange()" to a runtime created element [ using javascript ] :)
Vicky Vijay
Ranch Hand

Joined: Apr 23, 2008
Posts: 125
Roshan,

Are you trying to create a JSP TEMPLATE ?

i.e., Do you have any visual designer kind of concept in your application ?

After dynamic generation of JSP form elements,

Then... What would be your next process .. ?

Can you provide some insight on this ?
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
Yes..!! I would say it's kind of a Visual designer , though not exactly a drag and drop thing . It is actually a kind of far fetched idea right now .

Once the user is through with the cutomization Page , they would Save it . Once this is done the request generated would be saved [ i am still working on it ] .

A Final Page would be created based on the user Preferences and a link would be generated . Now you can distribute this link to anyone and they would be able to access the page .


In a normal scenario , since the FinalPage uses values from the customization page [ User Entered ] , and the page if accessed directly won't have these values so it would be showing blank elements / null .
Hence any request to the final page , the request would be replaced by the saved request and when sent to the requestDispatcher would show correctly .

If that clarifies anything..!!!
Vicky Vijay
Ranch Hand

Joined: Apr 23, 2008
Posts: 125
Roshan,

I guess you are looking for the Application like ORBEON FORMS,


Check out the below reference links...

1. DISPLAYS THE SUMMARY OF FORMS CREATED BY THE USERS

http://www.orbeon.com/orbeon/fr/orbeon/builder/summary

OPTIONS available here

"New" button --> This allows you to create the forms



2. VISUAL DESIGNER - You can create OWN FORMS

http://www.orbeon.com/orbeon/fr/orbeon/builder/edit/9b9be77450bddf6e579c4c06bfb141de


Once you have "SAVED" the forms, this would generate a "LINK" i.e., URL (this is similar to your requirement)

and all users can access the form based on the URL link


I hope your are trying SIMILAR/EXACT kind of concept to this..









Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 498
- You take the user input and save it into the DB.
- Next time, whenever somebody requests the template, you fetch it from DB , and draw the page.

This looks simple, unless I am missing something.
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
@Saurabh : Yes... But is it possible to save the request as such [ HttpServletRequest Object ] , Or would i need to read the inputStream and then the bytes .
and in such a scenario , how do i replace the request i.e. sending the request back to generate the Page .
Because i would need to send it as an object and the request has only inputStreams and Readers .

@ Guru Vijay : Yes this is exactly what i am trying to achieve . Thanks for providing the links . Will serve as a great inspiration .
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 498
Roshan Khandelwal wrote:@Saurabh : Yes... But is it possible to save the request as such [ HttpServletRequest Object ] , Or would i need to read the inputStream and then the bytes .
and in such a scenario , how do i replace the request i.e. sending the request back to generate the Page .
Because i would need to send it as an object and the request has only inputStreams and Readers .


Why do you want to play with the request? Is it not possible to implement it using DB? Honestly, I do not understand your way of implementation and I am not sure if it will work.
Roshan Khandelwal
Ranch Hand

Joined: Apr 16, 2009
Posts: 35
@ Saurabh : Pete in an earlier Post had also suggested the same thing . [ Using POJOs ] .

Actually i have been unable to understand the statement
Next time, whenever somebody requests the template, you fetch it from DB , and draw the page


Let' see " I fetch records from DB , in a POJO and then replace these values [ using some tag library ] into predefined areas in the jsp page right?? . This way i don't have to play with the request .
Saurabh Pillai
Ranch Hand

Joined: Sep 12, 2008
Posts: 498
Roshan Khandelwal wrote:@ Saurabh : Pete in an earlier Post had also suggested the same thing . [ Using POJOs ] .

Actually i have been unable to understand the statement
Next time, whenever somebody requests the template, you fetch it from DB , and draw the page


Let' see " I fetch records from DB , in a POJO and then replace these values [ using some tag library ] into predefined areas in the jsp page right?? . This way i don't have to play with the request .


E x a c t l y :)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Need to save a response , before sending it th the client
 
Similar Threads
Dynamic generation and removal of form elements in struts1
communication out.println and request parameter
Can a jsp page update itself using a servlet ?
What would be a proper way of reading a cookie in JSP
reading a form field.