对于JSP中的选择框,reqest.getParameter()返回null [英] reqest.getParameter() returns null for Select box in JSP

查看:82
本文介绍了对于JSP中的选择框,reqest.getParameter()返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在jsp文件(在Adobe CQ上)中有以下代码,但它返回null。不知道为什么。

 < select id =itemsperpage我预计out.println行会返回40,因为它是默认的选定值。 name =itemsperpage> 
< option value =20> 20< / option>
< option value =40selected> 40< / option>
< option value =100> 100< / option>
< option value =200> 200< / option>
< / select>
<%
字符串itemsPerPage = request.getParameter(itemsperpage);
out.println(Items:+ itemsPerPage);
%>


解决方案

您的代码将始终返回。尝试在运行应用程序后看到页面源代码项目的值总是 null



请尝试以下代码:(在此代码中,每当combobox的值发生更改时,我都会发送一个请求)

 < HTML> 
< head>
< meta http-equiv =Content-Typecontent =text / html; charset = ISO-8859-1>
< title>在此插入标题< / title>
< / head>
< body onload =form1.submit();>
< form action =#name =form1>
< select id =itemsperpagename =itemsperpageonchange =submit();>
< option value =20> 20< / option>
< option value =40selected> 40< / option>
< option value =100> 100< / option>
< option value =200> 200< / option>
< / select>
< / form>
<%
字符串itemsPerPage = request.getParameter(itemsperpage);
out.println(Items:+ itemsPerPage);
%>
< / body>
< / html>

[注意:我建议您不要使用 scriplets 在你的jsp文件中,而不是你可以去的AJAX,JSTL等]


I have the following code in a jsp file (on Adobe CQ) but, it returns null. Not sure why. I am expecting the out.println line to return 40 since it is the default selected value.

<select id="itemsperpage" name="itemsperpage">
<option value="20">20</option>
<option value="40" selected>40</option>
<option value="100">100</option>
<option value="200">200</option>
</select>
<%
String itemsPerPage = request.getParameter("itemsperpage");
out.println("Items: " + itemsPerPage );
%>

解决方案

your code will always return null. try to see page source after running your application. value of Items is always null.

try following code: (in this code I am sending a request on every time the value of combobox is changed)

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body onload="form1.submit();">
<form action="#" name="form1">
<select id="itemsperpage" name="itemsperpage" onchange="submit();">
<option value="20">20</option>
<option value="40" selected>40</option>
<option value="100">100</option>
<option value="200">200</option>
</select>
</form>
<%
String itemsPerPage = request.getParameter("itemsperpage");
out.println("Items: " + itemsPerPage );
%>
</body>
</html>

[Note: i will suggest you to not use scriplets in your jsp file, instead you can go for AJAX , JSTL etc. ]

这篇关于对于JSP中的选择框,reqest.getParameter()返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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