aspose file tools*
The moose likes Servlets and the fly likes How Do you pass data from the DataBase class back to the servlet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How Do you pass data from the DataBase class back to the servlet?" Watch "How Do you pass data from the DataBase class back to the servlet?" New topic
Author

How Do you pass data from the DataBase class back to the servlet?

Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
Perhaps here?

https://jstl.java.net/download.html
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42608
    
  65
Good guess :-) You need javax.servlet.jsp.jstl-api-1.2.1.jar and javax.servlet.jsp.jstl-1.2.1.jar.


Ping & DNS - my free Android networking tools app
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

And don't forget:


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
IT WORKS! IT WORK! IT WORKS!

A screen capture!
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
How difficult is it to attach the flight object to its corresponding details button in the same row and then shoot only that object to another JSP page?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18902
    
    8

Not hard at all. The button's URL would just have a parameter containing the flight number.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Raymond Gillespie wrote:How difficult is it to attach the flight object to its corresponding details button in the same row and then shoot only that object to another JSP page?


Don't think in term of "attaching the flight object". Once the page is sent to the browser, all objects, all JSP-ness, and all Java-ness is gone. All that remains is the text in the HTML page.

So, as Paul pointed out, you associate something that identifies the item you want associated. That could be something like the flight number, but more often any row of a database will have an id value that has no business meaning. it's just an id. What's best to use depends upon how things are looked up in the database, and how good the database schema designer was.
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
Bear Bibeault wrote:
Raymond Gillespie wrote:How difficult is it to attach the flight object to its corresponding details button in the same row and then shoot only that object to another JSP page?


Don't think in term of "attaching the flight object". Once the page is sent to the browser, all objects, all JSP-ness, and all Java-ness is gone. All that remains is the text in the HTML page.

So, as Paul pointed out, you associate something that identifies the item you want associated. That could be something like the flight number, but more often any row of a database will have an id value that has no business meaning. it's just an id. What's best to use depends upon how things are looked up in the database, and how good the database schema designer was.


At this point since all this is for practice, the database schema designer is me. Just for the sake of this exercise, I used the flightID as the primary key.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

For future reference, it is considered bad schema design to use a business field as a primary key. Generally, the primary key should be a number that has no meaning beyond being a unique identifier for the row. Usually, it's generated by a sequence if the database supports that.

But for now, if your primary key is the flight number, that's what you'd use to identify the item.

The key thing to take away, is that objects never get sent to a page. An HTML page is just that: HTML. So to associate items, you use their primary keys. When the next request comes in, the primary key is used to fetch the object anew.
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
SoI could create a hidden form field and have the primary key as an input value this way I could use request.getParameter to grab that value and then get that row from the database.

I am quite sure that would work but doesn't seem/sound like the best way to go about doing that. Seems more like a work around.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Well, it would have been fine 10 years ago -- but these days, JavaScript and Ajax would more likely be involved. But I take it that's not where your head is a t yet, is it?
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
Bear Bibeault wrote:Well, it would have been fine 10 years ago -- but these days, JavaScript and Ajax would more likely be involved. But I take it that's not where your head is a t yet, is it?


I know nothing of Ajax. I tried working with it one time on a PHP project but ended up going in a different direction.

I know I can move the text from page to page with JavaScript but I still need to interact with the database and several different servlets as the user goes from page to page. I am basically trying to go through an entire transaction process.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

JavaScript and Ajax do not interfere with that process. But for now, I'd say to stick with just form submissions until you've got all that down pat. Introducing Ajax before that will just make everything harder.

So I'd recommend to go ahead with forms and hidden inputs for now.
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
Bear Bibeault wrote:JavaScript and Ajax do not interfere with that process. But for now, I'd say to stick with just form submissions until you've got all that down pat. Introducing Ajax before that will just make everything harder.

So I'd recommend to go ahead with forms and hidden inputs for now.


Advice taken.

Just want to say thanks for the guidance and advice! It's really nice to be able to ask questions without being belittled when I don't understand something and especially when I do something that makes absolutely no sense what so ever.

I may run into something else so I am sure I will be back.

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

Glad to be of help. Everyone is a beginner in something at one point or another. Unfortunately, not all sites remember that.
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
That didn't take long huh. I have noticed that when clicking the back button, the data is gone. How do I make it stick?
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
Raymond Gillespie wrote:That didn't take long huh. I have noticed that when clicking the back button, the data is gone. How do I make it stick?


EDIT

When I say back button, I refer to the one I created on the page so I should be able to fix that, I hope.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61648
    
  67

What does this back button do, and why do you even have a redundant back button on the page?
Raymond Gillespie
Ranch Hand

Joined: Oct 08, 2012
Posts: 134
Bear Bibeault wrote:What does this back button do, and why do you even have a redundant back button on the page?


All it should do is go back to the previous page but of course you are correct in that it is redundant. I just got rid of it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How Do you pass data from the DataBase class back to the servlet?