Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Bear Bibeault wrote:Is your only issue that the address bar isn't changing? It won't! And it shoudn't. A forward is a server-side action of which the browser is not, and doesn't need to be, aware of.
Does the JSP display?
Marek Krokosinski wrote:Maybe I should make something like this:
Servlet connects to the db and saves the data to some variable. The new POJO class gets that data and saves it to the variable with getter/setter method. In the jsp page I import that POJO, or I use it as a bean and I get that variable by EL or <usBean>?
Paul Clapham wrote:
Marek Krokosinski wrote:Maybe I should make something like this:
Servlet connects to the db and saves the data to some variable. The new POJO class gets that data and saves it to the variable with getter/setter method. In the jsp page I import that POJO, or I use it as a bean and I get that variable by EL or <usBean>?
Sorry, I couldn't understand any of what you wrote before this. But this is the normal thing to do: a servlet receives the request and processes it by assembling the data required for the response. It puts that data into a request attribute, or several request attributes if necessary, and then forwards to a JSP. The job of the JSP is to produce the HTML for the response, inserting data from those request attributes as required.
You seem to be concerned with the page from which the request was sent. That page is in the past, you can't get anything from it (or whatever you were thinking). The JSP which generates the HTML must generate all of the HTML. Makes no difference if earlier requests generated similar HTML.
Marek Krokosinski wrote:I need the JSP page, with the data from database. The data which servlet should forward to the JSP page with the request. I want to enter that page by typing in the address bar www.someaddress.com/Page.jsp. And when I enter on that page I want to see the data from the database which servlet has forwarded.
Paul Clapham wrote:
Marek Krokosinski wrote:I need the JSP page, with the data from database. The data which servlet should forward to the JSP page with the request. I want to enter that page by typing in the address bar www.someaddress.com/Page.jsp. And when I enter on that page I want to see the data from the database which servlet has forwarded.
That doesn't make any sense. If you send a request from the browser directly to the JSP, then the servlet hasn't forwarded anything to the JSP. You can't even be certain that the servlet has ever run, so having the servlet put data into the session for the JSP to use later doesn't help.
Paul Clapham wrote:
I also couldn't make much sense of the rest of what you wrote. That's because the <c:forEach> loop which you mentioned has no context. If it's using data which was in request scope, then you're going to have to make sure that something earlier in the request actually put that data into the scope. If it's the servlet which is supposed to be doing that, then you have to make sure that the servlet ran earlier in the same request. And of course it's impossible for the JSP to make sure that a servlet ran earlier in the same request -- code can't affect what happened in the past.
But then you didn't say that the <c:forEach> loop was trying to use data from the request scope. You didn't say anything at all about it, in fact.
Marek Krokosinski wrote:I'm looking for way to display data from database in the JSP without making any request, without calling any servlet. Is it impossible?
Paul Clapham wrote:
Marek Krokosinski wrote:I'm looking for way to display data from database in the JSP without making any request, without calling any servlet. Is it impossible?
Of course it's impossible. If you don't send any request to the server then naturally it won't send you any responses.
However let's suppose you didn't really mean that. For some strange reason you don't want any servlets involved in processing the request you do send. Then you could put code into the JSP to get the data from the database. But the usual way to do things is (as I already said) to send the request to the servlet, to have it extract the data and forward to the JSP and so on. You seem to be resisting that idea. Why?
Bear Bibeault wrote: The <c:url> action will help you create a link that will call a servlet.
Bear Bibeault wrote:You always reference the servlet, not the JSP. Wherever you feel the urge to reference the JSP, just stop, and don't do it. Reference the servlet instead. It's really very very simple.
Bear Bibeault wrote:If you want to embed the result of processing the JSP at the point of include, yes.
This is one of the reasons that it's best to place the JSPs under a folder in the WEB-INF hierarchy. That way, you can't directly the JSP and always must go through its servlet controller. Takes the guesswork out of it.
Paul Clapham wrote:That wasn't what I asked, and it doesn't answer the question. You used relative URLs in your code. The specifications for JSP and for jsp:include tell you what URL they are relative to -- so look that up. I expect you are making an assumption about what they are relative to, and it isn't correct.
I’m tired of walking, and will rest for a minute and grow some wheels. This is the promise of this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
|