从JSP或HTML向Servlet发送多个参数 [英] Sending multiple parameters to servlets from either JSP or HTML

查看:178
本文介绍了从JSP或HTML向Servlet发送多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从JSP页面向Servlet发送特定的参数.例如:如果我单击网页上的Facebook图标,那么我应该将"facebook"作为参数发送到我的Servlet,然后我的Servlet将根据从JSP文件或HTML文件收到的参数进行响应.

I need to send a particular parameters to Servlet from JSP page. E.g: if I click on the Facebook icon on the web page, then I should send "facebook" as parameter to my Servlet and my Servlet will respond according to the parameter received from JSP file or HTML file.

推荐答案

只需将图标包装在带有查询字符串的链接中,例如

Just wrap the icon in a link with a query string like so

<a href="servleturl?name=facebook"><img src="facebook.png" /></a>

在servlet的doGet()方法中,只需按以下方法进行获取和处理即可

In the doGet() method of the servlet just get and handle it as follows

String name = request.getParameter("name");

if ("facebook".equals(name)) {
    // Do your specific thing here.
}

另请参见:

  • "Servlet信息"页面
  • See also:

    • Servlets info page
    • 这篇关于从JSP或HTML向Servlet发送多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆