This week's book giveaways are in the Cloud/Virtualization and Go forums.
We're giving away four copies each of Cloud Native Transformation: Practical Patterns for Innovation and The Go Workshop and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native Transformation: Practical Patterns for InnovationE this week in the Cloud/Virtualization forum
or The Go Workshop in the Go forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Knute Snortum
  • Henry Wong
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Joe Ess
  • salvin francis

Call method with JSTL

 
Ranch Hand
Posts: 32
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys!!

I'm new with JSTL and I need call a method static to list a combobox. I have tried, but I don't have sucess.
Follow the code below.

I need call this method(listCUrsos) in my JSP(view).

When I tried this, throw Exception.
Please anyone help me
 
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First of all, never just tell us you got an exception; show the exception.

Secondly, unless you are using JSP 2.2 (Tomcat 7) you can't call methods at all; just access properties.

And finally, even with JSP 2.2 you can't access a method on a servlet. Why would you put a method on a servlet? That's not the servlet's job.

Back up. Tell us what version of JSP you are using. And tell us what you are actually trying to accomplish. The fact that your method and variable names are not in English makes it hard to figure out without explanation.
 
William Flores
Ranch Hand
Posts: 32
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear Bibeault.
I'll try improve my explanation.

I need popular a combobox from database. I have a method DAO to do this

In my view I call that ServletRequisicao.listCursos to popular combobox.
Today I'm doing this with scriplet JSP, but I need change this to JSTL.
Follow the code to popular the combobox in scriplet

How I said I need change this to JSTL.
Do you understand?
 
Bear Bibeault
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The best practice way to to that is to fetch the information from the DAO in the servlet controller for the JSP. Then put that info in request scope and forward to the JSP. The JSTL can access the info through the scoped variable in request scope.

Have you read this article?
 
William Flores
Ranch Hand
Posts: 32
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The combobox needs to be popular before loads the page. How can I call that method in ServlerRequisicao?
In the ServletRequisicao It has others method to popular others combobox and checkbox.
 
Bear Bibeault
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

William Flores wrote:The combobox needs to be popular before loads the page. How can I call that method in ServlerRequisicao?


There's no combo box on the web (correct terminology is important in programming). Read HtmlHasNoComboBox.

Also, the word you want is populate, not popular.

The servlet serving as the page controller should have a doGet method that's invoked when the JSP is to be displayed. In that doGet method, it is the job of the controller to gather any data needed to display the page.

The controller does all the hard work so that the JSP is as simple as possible.

In the ServletRequisicao It has others method to popular others combobox and checkbox.


What is the purpose of those other methods? The page controller should not have methods other than that needed for its page.

If those methods are to support other pages, they should be in the controllers for the other pages.

It also appears that you are putting model methods in your controllers. Those methods should be in model classes.

Did you read the article?
 
William Flores
Ranch Hand
Posts: 32
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading the article
 
Bear Bibeault
Marshal
Posts: 67334
170
Mac Mac OS X IntelliJ IDE jQuery Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cool. It should give a you a good idea of best-practice structure for web applications.
 
Hey! Wanna see my flashlight? It looks like this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!