我在jsp页面中有锚链接,如下面<td>
表中所示。
<td>
<span>
<a href="AddDescriptionForEvent.jsp?" name="count"><%=(cnt)%></a>
<span>
</td>
此处{440} scriplet内的cnt
是一个整数。标签位于<form>
的{{1}}和action
属性中,指向正确的下一页。
我必须在下一页中获取该整数的值。
我正在使用如下,
<form>
此处int day = nullIntconv(request.getParameter("count"));
会将nullIntconv
转换为string
。
但我没有得到我选择的价值。它总是给我0。
请建议。
答案 0 :(得分:2)
您的href需要进行一些更改, 一个href不会作为表单元素提交(例如textbox,textarea等..)
尝试使用这样的..
<td><span> <a href="AddDescriptionForEvent.jsp?count=<%=(cnt)%>">Click to get count</a><span></td>
In Above count将作为查询字符串发送 在下一页上,从请求中读取计数...
String c= request.getParameter("count");
if(c!=null)
{
int count=Integer.parseInt(c);//converting back into integer
}
-----您的自定义代码----------
答案 1 :(得分:0)
<a>
无法按照您的意愿使用。对于<form>
,<input>
,<textarea>
之类的提交,它不是依赖于<select>
的HTML元素之一。
您可以详细了解如何使用<a>
here以及如何在网址here中传递请求参数。还有关于HTML form and its elements的事情。
所以,如果您的代码是这样的:
<form action="/AddDescriptionForEvent.jsp" name="myForm">
<td>
<input type="text" name="someText" value="some Value" />
</td>
<td>
<span>
<a href="AddDescriptionForEvent.jsp?" name="count"><%=(cnt)%></a>
<span>
</td>
<input type="submit" value="Press me to Submit" />
</form>
然后点击submit
按钮,您只会发送输入someText
而不是count
的值。
要将count
的值与其他值一起发送,请使用以下格式:
<form action="/AddDescriptionForEvent.jsp" name="myForm">
<td>
<input type="text" name="someText" value="some Value" />
</td>
<td>
<span>
<!-- changed the <a> tag to <input> -->
<input type="text" name="count" value="<%=(cnt)%>" />
<span>
</td>
<input type="submit" value="Press me to Submit" />
</form>
或者您可以在没有<form>
的情况下使用以下内容:
<td>
<span>
<a href="AddDescriptionForEvent.jsp?count=<%=cnt%>">Click this link to Add</a>
<span>
</td>
<!-- Notice the placement of the "cnt" variable of JSP -->
要点击此<a>
链接同时传递其他参数,请将href
修改为href="AddDescriptionForEvent.jsp?count=<%=cnt%>&someText=some value"
这是你可以达到预期效果的两种方式。你的java代码获取请求参数很好。
答案 2 :(得分:0)
&LT;%=(CNT)%&GT;
坚持
使用
“name =”count“&gt;&lt;%=(cnt)%&gt;
答案 3 :(得分:0)
thanks for all your replies.
I did like this in the main page, added id
<td align="center" height="35" id="day_<%=(cnt)%>">
<span><a href="AddDescriptionForEvent.jsp?id=<%=(cnt)%>"><%=(cnt)%></a></span></td>
And in the next page i got the required output as
int d=nullIntconv(request.getParameter("id"));
Where nullIntconv is the string to integer converter.