Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

passing data

 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Using what server-side technology?
 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry about the smiley-it should be :param
 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not really an HTML question, so I'm moving this off to the JSP forum.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Pat Peg
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic