gpt4 book ai didi

java - 将值从 JSP 发送到 servlet

转载 作者:太空宇宙 更新时间:2023-11-04 07:42:23 24 4
gpt4 key购买 nike

我在 JSP 中有一个对象列表,并且希望根据单击的超链接将值发送回 servlet。我的代码如下所示。

<body>
<h1>Choose a Festival</h1>
<jsp:useBean id="allFestivals" type="java.util.ArrayList" scope="session" />
<table border ="1">
<tr>
<td>Festival Name:</td>
<td>Location:</td>
<td>Start Date:</td>
<td>End Date:</td>
<td>URL:</td>
<td>List of Trips to </td>
</tr>
<c:forEach items="${allFestivals}" var="allFestivals">
<tr>
<td>${allFestivals.festivalName}</td>
<td>${allFestivals.location}</td>
<td>${allFestivals.startDate}</td>
<td>${allFestivals.endDate}</td>
<td>${allFestivals.URL}</td>
<td>
//THE ISSUE IS IN THIS FORM, I SUPPOSE SYNTAX ISSUE
<form name="linkChecker" method="get" action="ControllerServlet">
<input type = "hidden" value="${allFestivals.ID}" name="festivalProfileLink" />
<a HREF ="javascript:document.linkChecker.submit()">View Related Trips</a>
</form>
</td>
</tr>
</c:forEach>
</table>

<a href="logout.jsp">Logout</a>

</body>

和 servlet GET 方法:

 @Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

String aa = request.getParameter("festivalProfileLink");
JOptionPane.showMessageDialog(null, aa);
if("hello".equals(aa)) {
JOptionPane.showMessageDialog(null, "dfgdfgdf");
}
}

目前没有信息(或至少没有值)发送到 servlet

最佳答案

您正在发出 POST 请求,您不会在 doGet() 中获得结果,请尝试在 doPost()

根据对帖子的编辑来编辑答案

对于这种类型的操作 GET 非常适合,您只需生成链接即可

按照建议here in your earlier post您应该生成将传递参数的链接通过网址

通过这种方法,我怀疑您在错误的路径上发布,您可以使用 firebug 进行调查

关于java - 将值从 JSP 发送到 servlet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15857053/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com