单击超链接调用servlet [英] Call a servlet on click of hyperlink
本文介绍了单击超链接调用servlet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法在不使用JavaScript的情况下点击超链接调用Java Servlet?
Is there a way to call a Java Servlet on click of hyperlink without using JavaScript?
推荐答案
使超链接有一个您在 web.xml
文件中定义了servlet映射的URL。
Make the hyperlink have a URL that you have a servlet mapping defined for in the web.xml
file.
servlet-mapping
元素定义了servlet和URL模式之间的映射。下面的示例将名为 myservlet
的servlet映射到以 / foo
开头的任何URL:
The servlet-mapping
element defines a mapping between a servlet and a URL pattern. The example below maps the servlet named myservlet
to any URL that starts with /foo
:
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>com.stackoverflow.examples.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/foo/*</url-pattern>
</servlet-mapping>
- 对于此示例,超链接如
< a href =/ foo / test.html>点击我< / a>
将调用servlet。 - For this example, a hyperlink such as
<a href="/foo/test.html">Click Me</a>
would invoke the servlet.
这篇关于单击超链接调用servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文