views:

36

answers:

1

Is it possible to call a spring controller from javascript included in a jsp? I'm trying to call it like this:

form.action='${pageContext.request.contextPath}/spring/myController';

I can see that the control passes throught the lines, but nothing is happening.

Also I get messages like get or post is not supported. when I submit the form with a post method I get error message post is not supported. I use the annotations like this in controller.

@RequestMapping(method = RequestMethod.GET)

How can I handle both get and post in spring controllers?

+1  A: 

Your javascript is not actually calling anything. Rather, it is setting the "action" attribute of (I assume) a <form> element in your web page to some URL assembled by the JSP. The "call" to your server will happen later ... when the user clicks some button that causes the form to be submitted.

Stephen C
that was correct. I added a form.submit(). Now it's submitting the form.
coder247