Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP does not call the right method in the controller class

 
R Naijat
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:
http://localhost:8080/dir/list

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:

http://localhost:8080/dir/list/true/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:
http://localhost:8080/url/list//?newItems=%23&rejectedItems=%23&apply=Apply

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:

http://www.w3schools.com/tags/tag_form.asp

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:

<input>
<textarea>
<button>
<select>
<option>
<optgroup>
<fieldset>
<label>
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.
 
Stefan Evans
Bartender
Posts: 1822
10
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!