aspose file tools*
The moose likes JSP and the fly likes passing data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "passing data" Watch "passing data" New topic
Author

passing data

Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
Can someone please give me a simple example of how to pass data from one page to another? Actually what I want to do is re-build a page which looks like a form after the user commits a search on a specific item. He would type into a text field and then I am implementing a database call that will over-write the data fields with data from the db if the search was a good one.

Thanks
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

Using what server-side technology?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
I'm using Tomcat if that is what you mean.

I am trying

I want vale to be the same value I was given on this page when I did



but I don't know how to set the parameter if the paramenter is in a java string. Did that make since?
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
Sorry about the smiley-it should be :param
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
I feel a need to explain myself...
page 1 user gives me a string to search on using something like


page 2 is where I have

followed by all my database connect stuff (this page is invisible to the user and is only there for control

If id is in the database i want to pass it on to page 3 (which is where the user thinks he was going anyway) but I am not sure how to now pass that value on.

and thanks for being there at this hour
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61066
    
  66

This is not really an HTML question, so I'm moving this off to the JSP forum.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

With server side Java, there are more slick patterns for handling these types of transactions.

If you haven't yet, it would be worth your time to find a good book or tutorial on servlets and JSP. I recommend "Core Servlets and Java Server Pages" by Marty Hall.

In particular look for a good explanation of JavaBeans, and MVC.
If done right, you can achieve a complete separation between your database, webflow, and display code.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Pat Peg
Ranch Hand

Joined: Feb 04, 2005
Posts: 194
Yes, I am aware of that MVC would be better but I am in a pinch and need to throw something together in very short order so I need to go with what they already have in place. I am just adding to an already clumbsy design and no one wants to give the time to do it right. Is there any direction you can give me?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

There are three objects to which variables can be bound in order to pass them from one component (page, in this case) to another.

JSP provides implicit object variables for you.

These objects are:
  • context
  • session
  • request


  • Objects bound to the context object are said to be in context (think application) scope and will last until your application is restarted.

    Likewise, session scoped objects last for the duration of the user's session and request scoped object last for the duration of 'this' request.

    You bind the variables to the scoped objects with the .setAttribute(String, Object) method and retrieve them with the .getAttribute(String) method.

    That should get you by.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: passing data