This week's book giveaway is in the Jython/Python forum.
We're giving away four copies of Murach's Python Programming and have Michael Urban and Joel Murach on-line!
See this thread for details.
Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Loading servlet JSP  RSS feed

 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

I have a list where you want to load a servlet when opening the jsp page.
What is the best practice for this?
As you would it?
I tried to make an onload in the body, but did not carry the data.

Thank you
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65826
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sounds kind of backwards. A servlet should serve as the controller and invoke the JSP page -- not the other way around.

Have you read this article on proper web application design and structure?
 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My situation is as follows:
Have a customer base where you want to list the states, it would be incorrect?

Thank you

 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct. It' snot loading a servlet though. It is getting data that you've already put as a request or session attribute when you called the servlet previously.
 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As would be made this call? I tried to make the onload in the body, but to no avail.
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
${Luf.id} is called EL (expression language). It runs when the JSP executes. The last step in the process before HTML is sent to the browser.
 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not loading, it loads only if I make an action on a form.
My servlet's service method with.
 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene Ribeiro wrote:It is not loading, it loads only if I make an action on a form.
My servlet's service method with.

To make it more clear, there should be a servlet, In that servlet you should create and populate "listaUf".
You have to set that in a request attribute.
Then control goes to JSP and you will have your values there to iterate.
 
Rene Ribeiro
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need my JSP load the UFs in servlet.

My Servlet



Minha Class DAO

 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rene Ribeiro wrote:I need my JSP load the UFs in servlet.

So I am getting confused here by the above statement.
JSP does not load objects in servlet.
In your case servlet should get all the data from DAO you want to display in front end.
Those data should be passed to JSP and formatted accordingly for display.

BTW few things about the code.
  • You have used ClienteDAO class in servlet, but did not post the code of that class.
  • You have posted the code of UfDao class, but never used that in servlet.
  • Avoid creating public member variables in class. Member variables SHOULD always be private.
  • Release the SQL objects in finally block, otherwise they will cause the database to throw exceptions after maximum connections/cursors are used.
  • Servlets have doGet() and doPost() methods. Use them.
  •  
    Rene Ribeiro
    Ranch Hand
    Posts: 35
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    I'm not using doPost or doGet because they are not being submitted but only loaded without user interaction. To use the doPost or doGet I need is coming from a form.

    As I need to fill a ComboBox, as you would using this list?


     
    Tapas Chand
    Ranch Hand
    Posts: 614
    9
    BSD Java
    • Likes 1
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Rene Ribeiro wrote:I'm not using doPost or doGet because they are not being submitted but only loaded without user interaction. To use the doPost or doGet I need is coming from a form.

    There is no need to do all these.
    Either
    You pass all the required data when you are going to JSP from Servlet for the very first time (Are you going to the JSP from a Servlet?)
    Or
    You do an AJAX call from the JSP and fetch required data without submitting the form.
     
    Consider Paul's rocket mass heater.
    • Post Reply Bookmark Topic Watch Topic
    • New Topic
    Boost this thread!