单击单选按钮时调用 servlet
我想在单击单选按钮时调用 servlet,我该如何实现?
编辑
我尝试在 javascript 函数中将 URL 添加到 servlet,就像这样
$.post( "ParentManagementServlet", "isActivated");
,这样
$.post(<%=getServletContext().getContextPath()+"/ParentManagementServlet"%>, "isActivated");
,这样,
$.post("/ParentManagementServlet?isActivated=true");
但是两者都不调用 servlet!
这是 web.xml 中 servlet 的 url 映射
<servlet>
<servlet-name>ParentManagementServlet</servlet-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>
我通常通过名称添加 servlet,但我读到最好从 servlet 上下文中获取 servlet 绝对路径。
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</servlet-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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
根据评论:
$
由 jQuery 定义。您显然没有在您的页面中声明它。 jQuery 是一个 JS 库,而不是浏览器或其他内置的东西。将以下行放在
中的任何其他
之前
(当然,您也可以从您自己的域)
另请参阅:
As per the comments:
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>
(you can of course also download and serve a copy from your own domain)
See also:
使用阿贾克斯。例如,使用 jQuery:
Use ajax. For example, with jQuery:
要在用户选择单选按钮(没有提交按钮)时及时调用 servlet,请使用:
示例:
在其他情况下,想法是相同的:绑定 Servlet,选择将触发 servlet 的事件
To call servlet in time when user select radio (without submit button) use:
example:
In other situation the idea is the same: bind Servlet, choose event which will be trigger the servlet