aspose file tools*
The moose likes Servlets and the fly likes Getting the name of the requesting page 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 » Servlets
Bookmark "Getting the name of the requesting page" Watch "Getting the name of the requesting page" New topic
Author

Getting the name of the requesting page

Ravi Sree
Ranch Hand

Joined: Jan 24, 2010
Posts: 62

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

Joined: Jan 24, 2010
Posts: 62

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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12682
    
    5


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

Java Resources at www.wbrogden.com
Ravi Sree
Ranch Hand

Joined: Jan 24, 2010
Posts: 62

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).

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60074
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Ravi Sree
Ranch Hand

Joined: Jan 24, 2010
Posts: 62

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
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60074
    
  65

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

Joined: Jan 24, 2010
Posts: 62

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Getting the name of the requesting page
 
Similar Threads
Form Bean scope problem
Struts form bean scope
Dealing with backing bean on request scope ?
Moving a bean from request to session context
Page Beans