栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

使用以下命令将值从jsp传递到servlet [](file:///C://Users//ghz//Desktop//all//CodingDict-Local//%E7%88%AC%E8%99%AB

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

使用以下命令将值从jsp传递到servlet [](file:///C://Users//ghz//Desktop//all//CodingDict-Local//%E7%88%AC%E8%99%AB

[

如果要使用URL将参数发送到servlet,则应采用这种方式

<a href="goToServlet?param1=value1&param2=value2">Go to servlet</a>

然后检索将在请求中可用的值。

关于第二个问题。我会说不。您可以在URL中添加参数,例如

<a href="goToServlet?method=methodName&param1=value1">Go to servlet</a>

并使用该信息来调用特定方法。

顺便说一句,如果您使用Struts之类的框架,这将更加容易,因为在Struts中,您可以将URL绑定到特定的Action方法(比如说“ servlet”)

编辑

您已通过以下方式定义了servlet:

@WebServlet("/servlet123")

](file:///C://Users//ghz//Desktop//all//CodingDict-
Local//%E7%88%AC%E8%99%AB//pages//jsp/page_36_09.html)

您,您的servlet将在/
servlet123上可用。请参阅
doc。

我已经测试过您的代码,并且可以正常工作:

@WebServlet(name = "/servlet123", urlPatterns = { "/servlet123" })public class Servlet123 extends HttpServlet {    @Override    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {        resp.setContentType("text/html");        PrintWriter out = resp.getWriter();        out.write("<h2>Hello Friends! Welcome to the world of servlet annotation </h2>");        out.write("<br/>");        out.close();    }}

然后,我在中调用servlet

http://localhost:8080/myApp/servlet123
(如果使用myApp,则将其作为应用程序上下文)。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/466623.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号