| Author |
Pizza and Servlets
|
Alen Mester
Greenhorn
Joined: Jul 08, 2011
Posts: 21
|
|
Good Day!!!
Maybe the name of the subject sounds weird but I have a problem. I want to show a list of pizzas in a jsp. (Other ideas like the login , register of pizzas, register of users are working but this one no)
this is my servlet
this is part of the dao
and finally the jsp
Any solution for my problem
thanks
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
After posting all of that code you never got around to explaining your problem.
Edit: But I should ask this... are you requesting the servlet with a GET request or a POST request?
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Alen Mester wrote:Any solution for my problem
That greatly depends upon what the problem is. You haven't said.
(P.S. Properly indenting your JSP code will make it far easier to read.)
[Edit: Paul is making a habit of sneaking his posts in before me. ]
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Alen Mester
Greenhorn
Joined: Jul 08, 2011
Posts: 21
|
|
Thanks .
What I want is to show a list of pizzas in the jsp.
the problem: I dont see the list on the jsp. so the problem I think is in the servlet in the get request.
the POST request was used to save the data in the database and was successful.
The JSP
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
So you're sending two requests, a get and a post? That seems kind of peculiar, but anyway, which order do they get sent in?
Also, it isn't obvious to me how your "new DaoPizzas()" object in the doGet() method gets data into it. Perhaps there's some code in the constructor which goes out to the database to get all of the data?
Edit: Never mind, you did post the code which does that. However the doGet() method doesn't do anything with that data. It just returns without putting anything in the response, as far as I can see.
|
 |
Arun Giridharan
Ranch Hand
Joined: Sep 30, 2010
Posts: 290
|
|
|
Instead of using doGet() or doPost() you can use service() , based on the URI you can handle the request ,check your List in the requestScope.
|
 |
Alen Mester
Greenhorn
Joined: Jul 08, 2011
Posts: 21
|
|
Thanks again.
the service() , is new for me... -_- I have to look for that.
So the doGet() method returns nothing, let me check for it as well
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
Alen Mester wrote:the service() , is new for me... -_- I have to look for that.
No, don't waste any time on that. That's bad advice for the majority of web site designers. You ought to design your web applications to use "get" and "post" methods appropriately, and once you have done that, you ought to use the doGet() method to handle "get" requests and the doPost() method to handle "post" requests. Using the service() method allows you to avoid having to make those decisions -- which are decisions you ought not to avoid.
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
Paul Clapham wrote:
No, don't waste any time on that. That's bad advice for the majority of web site designers. You ought to design your web applications to use "get" and "post" methods appropriately
Quoted for truth! The suggestion to use service() was not a good one.
|
 |
Arun Giridharan
Ranch Hand
Joined: Sep 30, 2010
Posts: 290
|
|
Paul Clapham wrote:
Alen Mester wrote:the service() , is new for me... -_- I have to look for that.
No, don't waste any time on that. That's bad advice for the majority of web site designers. You ought to design your web applications to use "get" and "post" methods appropriately, and once you have done that, you ought to use the doGet() method to handle "get" requests and the doPost() method to handle "post" requests. Using the service() method allows you to avoid having to make those decisions -- which are decisions you ought not to avoid.
but paul i can use the request uri to find from where i'm getting the request and based on that i can do my operation , or it's really that bad ?
In my project servlet + jsp , i have done like this
web.xml
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
You can still do that from doGet and doPost. If you really want the two methods to do the same, just call one from the other. By overriding service you are removing support for HEAD, OPTIONS and TRACE. Do you really want that?
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56204
|
|
|
One of the worst habits that web developers seem to have (besides putting Java code in JSPs) is not understanding how GET and POST should be used. At a simplified level, GET should be used for getting resources and POST for performing operations.
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1005
|
|
What I don't see here is a connection between your doGet method and a JSP to display the list of pizzas.
You retrieve the list of pizzas
You set it as a request attribute
You.... do nothing else ...
What I would expect to see here is some display of this list of pizzas.
For instance:
|
 |
Paul Clapham
Bartender
Joined: Oct 14, 2005
Posts: 16483
|
|
|
I already asked why there were separate doGet and doPost methods, and I thought I got the answer that two requests were sent. I asked why and got no answer. I suspect that's because only one request is really being sent. Which would then raise the question, why are there separate doGet and doPost methods?
|
 |
Stefan Evans
Bartender
Joined: Jul 06, 2005
Posts: 1005
|
|
The get and post methods are for two different requests.
The get request gets the list of Pizzas available - action == displayPizzaMenu
The post request is for adding a new pizza to the list - action == addPizzaToMenu
In a lot of code I have written, doGet and doPost are coded to do the same thing, so it doesn't matter which you use. My default implementation of doGet is to call doPost.
In fact thats such a common pattern that I didn't think of doing it another way.
To my mind, the get/post methods in this example are equivalent to actions in a framework like Struts/Stripes/JSF. Using a framework like that would allow them to be named better, however it accomplishes the same thing.
At least thats my read on whats going on.
|
 |
Alen Mester
Greenhorn
Joined: Jul 08, 2011
Posts: 21
|
|
Godd Morning !!
I appreciate the help. The only I need it was the
This topic is closed
|
 |
 |
|
|
subject: Pizza and Servlets
|
|
|