Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

JSP does not call the right method in the controller class

Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have a jsp file which loads a page at this address: http://localhost:8080/dir/list/

I've added two checkboxes to the page; user can check both checkboxes, only one or none. Following is code I have in jsp file:

This is my Controller class:

The way my jsp code is written now, it calls the correct method and displays the correct url. When page loads for the first time, it calls method1 and the url is:

When the user checks/unchecks one or both checkboxes and clicks on apply button, method3 is called and this url is displayed:

If both checkboxes are checked which both booleans are set to true:


Everything is fine... however, if I comment these two lines at the end of JavaScript apply() function,

Then method3 will never gets called; only method1 gets called and I see this url:

I do not know why it gets confused bet. method1 and method3 and cannot pick the right method?

I tried to use the POST method instead, but the page goes directly to our internal error page and it never reaches the method I wrote in my controller for POST:

So I got rid of POST alltogether...

I cannot use the GET method correctly either... I don't really know what I'm doing wrong? Any help is greatly appraciated.
R Naijat
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I changed the <form> in the jsp to <div> and its working fine. I do not need to have comments in JavaScript funcion() anymore. I don't know why that made the difference though? According to:

The <form> tag is used to create an HTML form for user input.

The <form> element can contain one or more of the following form elements:

An HTML form is used to pass data to a server.

I do have <button> and also send the data - the value of checkboxes - to server. So I think it should also work with <form>.

Please let me know if you have any idea. Thanks.
Posts: 1845
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you need to go and read about basic HTML form elements

It appears you're not using the form tag at all, and just using javascript to navigate to a new url with parameters.
If you actually want to use the form it should be more like:

and instead of that hacky button in an anchor tag, make it an <input type="submit"/>.
That will submit the form to the url specified in the action, along with parameters being the controls nested in the form.

The @RequestMapping annotation is a Spring annotation. You might have better luck in the Spring specific forum than the JSP one.
There is no "i" in denial. Tiny ad:
Thread Boost feature
    Bookmark Topic Watch Topic
  • New Topic