call servlet when radio button is clicked
I want to call servlet when radio button is clicked, how can I make it?
EDIT
I tried to add URL to servlet in javascript function like this
$.post( "ParentManagementServlet", "isActivated");
and like this
$.post(<%=getServletContext().getContextPath()+"/ParentManagementServlet"%>, "isActivated");
and like this
$.post("/ParentManagementServlet?isActivated=true");
but both does not call servlet!
here's the url mapping of the servlet in web.xml
<servlet>
<servlet-name>ParentManagementServlet</servle开发者_Go百科t-name>
<servlet-class>ps.iugaza.onlineinfosys.servlets.ParentManagementServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ParentManagementServlet</servlet-name>
<url-pattern>/ParentManagementServlet</url-pattern>
</servlet-mapping>
I usually add the servlet through its name, but I read that it's better to get the servlet absolute path form servlet context.
As per the comments:
about fireBug, here's what returns $ is not defined
The $
is definied by jQuery. You've apparently not declared it in your page. jQuery is a JS library and not something already builtin the browser or something.
Put the following line before any other <script>
in your <head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
(you can of course also download and serve a copy from your own domain)
<script src="jquery-1.5.2.min.js"></script>
See also:
- Update current page with Servlet - contains several complete jQuery-Servlet examples
Use ajax. For example, with jQuery:
...onclick="invokeServlet()"
function invokeServlet() {
$.post("/path/to/servlet", params);
}
To call servlet in time when user select radio (without submit button) use:
- Add appropriate mapping to your Servlet - Bind some URL to servlet.
- use onselect attribute to call javascript function, which will redirect to the URL
example:
<input type ="radio" Value="blah blah" onSelect="yourFunction()"/>
In other situation the idea is the same: bind Servlet, choose event which will be trigger the servlet
精彩评论