File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Call method with JSTL

 
William Flores
Ranch Hand
Posts: 32
Chrome Eclipse IDE
  • 0
  • 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
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
Chrome Eclipse IDE
  • 0
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
Chrome Eclipse IDE
  • 0
  • 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
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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
Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm reading the article
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • 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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic