• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Getting the name of the requesting page

 
Ranch Hand
Posts: 64
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am working on a project which uses MVC 2 approach.
View - HTML and JSP, Controller- a servlet, Model - beans,
business and data access layer, etc.
I want to populate the view data as a (form)bean.
i tried with common setProperty and getProperty but
using wasnt very satisfied as the useBean facility works in session scope.
but not as required (as per the project) for scope request as in struts framework.
hence I am trying to build the (form)bean at the server-side to be easy to process via a filter.
But for that i want to know if address of the page from which the request is generated can be determined.
Please reply if this is right, and if there is any other alternative.

Thanks in advance.

 
Ravi Sree
Ranch Hand
Posts: 64
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi again,

This is the example i tried out for passing form parameters to the servlet from jsp

MyServlet.jsp


MyBean.java

web.xml

index.jsp

result

This is one of my steps where i could make a thorough understanding of a MVC 2 architecture.
Please suggest where am i going wrong and what should be done here, so as to get the form parameter in request scope in the itself servlet end,
I had read something about common.beanUtils but havent used it yet.
I will be very thankful if any solution, example, or links are provided.

Thanks in advance.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


How is the request expected to get a reference to your bean? Where is the setAttribute code?

What does JSP have to do with anything here? JSP writes a HTML page to the client browser, if that includes a FORM which does a POST to the servlet, you can only get String values from the request parameters.

Bill
 
Ravi Sree
Ranch Hand
Posts: 64
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

William Brogden wrote:

How is the request expected to get a reference to your bean? Where is the setAttribute code?

What does JSP have to do with anything here? JSP writes a HTML page to the client browser, if that includes a FORM which does a POST to the servlet, you can only get String values from the request parameters.

Bill


Hi William,

Thanks for replying.

I intended to pass the form parameter data using useBean, and expecting it to get in th request scope at the servlet end.
Hence the form parameters assinging to the properties with <jsp:setProperty name="myBean" property="*"/>
Please suggest if there is any other way by which i can assign the parameters to the form bean in jsp in request scope to be accessed by the servlet(controller).

 
Sheriff
Posts: 67753
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
You can't.

The request that generates the HTML page created by the JSP goes away when the response is sent to the browser. So any scoped variables in request scope go away with it.

You can only submit form elements from the page back to the server. So you can capture the data in hidden form elements if that's appropriate.
 
Ravi Sree
Ranch Hand
Posts: 64
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:You can't.

The request that generates the HTML page created by the JSP goes away when the response is sent to the browser. So any scoped variables in request scope go away with it.

You can only submit form elements from the page back to the server. So you can capture the data in hidden form elements if that's appropriate.



Hi Bear,

Thanks for replying,

What i want to do is keep the form parameter in request scope.
Since as you said, this scoped variable is not able to persist the data,
And assigning them to session scope is not a very appropriate way,
since I plan to save only data as username, etc in session object.
I though of using the ServletFilter as alternative way, where i thought of
recognizing the url from which the request was generated accordingly map parameters
in the bean class and assigning them in request scope (so the subject of the question, please don't mind).
But could think of a good way to do that too.

I did some study with struts source code, but was not very comfortable with
going for designing tags for the same as it it seems in struts1.2.9.

This isn't the actual project i am working on,
The project contains HttpServlet as the controller which analyses the url (for eg: "/user/Register")
and passes the control to appropriate action which has the calls the business layer which
in turn may call data access layer and as per the result returns the url as string which the servlet
uses to forward using normal request dispatcher.
As of now i am using the Form parameters as in a Hash map as opposed to in a bean,
Hence to add another level of effectiveness as per the MVC2 approach beans has to be
the carriers of the data in every level, i am looking for the simple but most effective solution.

Please suggest if any other way is there.
 
Bear Bibeault
Sheriff
Posts: 67753
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
To be honest, after reading this topic through, I'm still not sure what you are really trying to accomplish.

If all you want to do is to pre-populate a form with values, that's pretty striaght-forward and doesn't require all the complications methioned in this topic.

So what are actually trying to do?
 
Ravi Sree
Ranch Hand
Posts: 64
MySQL Database PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:To be honest, after reading this topic through, I'm still not sure what you are really trying to accomplish.

If all you want to do is to pre-populate a form with values, that's pretty striaght-forward and doesn't require all the complications methioned in this topic.

So what are actually trying to do?


Hi,

That was just the project design i am working on

Please let me explain with an example :

web.xml

FormBean.java

DBHandler.java

forms.properties

process.jsp

retry.jsp

success.jsp


I want to do this kind of form processing but without using process.jsp as in this example.
Although i went through few of the struts source code, havent fully understood
how the parameters are bound to the form-bean (Action-Form) after submitting the form.
I was hoping if this kind of form processing can be done,
even though if it may not be an easy task for wrting a generic method to bind the form parameters .
so that the controller's 'Action' can use the bean in request itself.

Please bear with me and guide if my understanding is not right.
 
There will be plenty of time to discuss your objections when and if you return. The cargo is this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic