File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Call method with JSTL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Call method with JSTL" Watch "Call method with JSTL" New topic
Author

Call method with JSTL

William Flores
Ranch Hand

Joined: Dec 14, 2011
Posts: 30

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

Joined: Jan 10, 2002
Posts: 61606
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
William Flores
Ranch Hand

Joined: Dec 14, 2011
Posts: 30

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

Joined: Jan 10, 2002
Posts: 61606
    
  67

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

Joined: Dec 14, 2011
Posts: 30

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

Joined: Jan 10, 2002
Posts: 61606
    
  67

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

Joined: Dec 14, 2011
Posts: 30

I'm reading the article
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Cool. It should give a you a good idea of best-practice structure for web applications.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Call method with JSTL