PDA

View Full Version : Handling events in jsp page



kindly10
Aug 7th, 2010, 11:17 AM
i am new in Spring

I have a jsp page using spring framework and i have a controller file .
i put 2 button on page and wrote 2 method for them .
one on them is
<input type="button" value="add" onclick="doAdd"/>
and method for this button is
doAdd(){
......
} wrote in controllet

next one is
<input type="button" value="delete" onclick="doDelete"/>
and method for this button is
doDelete(){
....
} wrote in controllet

how can i do it.
please help me soon .

jamestastic
Aug 7th, 2010, 12:57 PM
The onclick attribute is only used for calling JavaScript functions. It does not directly invoke anything on the server (such as a server-side controller method). Further, it is generally bad practice to use the onclick attribute directly, because it instantly requires your users to have browsers with JavaScript support. JavaScript events like these should be reserved for enhancing an already working web page, meaning if a non-JavaScript-compliant browser is used, the web page will still fully function.

As for your particular use case, you would likely want to use links to request a path on your server mapped to the two controller methods you described.

For example, you could have <a href="/mysite/delete">Delete</a>, and a controller method annotated with @RequestMapping("/delete").

There is quite a lot to learn, and the Spring Reference (http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mvc.html) is a great place to start.