请求参数值在包含空格时被截断为第一部分 [英] Request paramter value is truncated to first part when it contains spaces

查看:24
本文介绍了请求参数值在包含空格时被截断为第一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

jsp/servlet 中的下拉框有一个奇怪的问题.这是……

I have a strange issue with dropdown boxes in jsp/servlet. Here it is...

  <select name="locdropdown" onchange="javascript:change()" > 
<%
for(LocationDO locationDO : locationList){%>
<option value=<%=locationDO.getLocationName().trim()%>><%=locationDO.getLocationName().trim()%></option> 
<%} %>
</select>

显示的值为:

 BI Sholingar
 BI Mahindra City
 BI Sanand 
 Rolltec_DTA
 Aztec Auto Ltd
 BI Gurgoan

这是我尝试在 servlet 中读取它的方式.

and here is how I try to read it in servlet.

String locclasses = req.getParameter("locdropdown");
System.out.println(locclasses);

假设我选择了 Aztec Auto Ltd 然后 servlet 的预期输出是相同的.但输出是Aztec.同样,如果我选择 BI Sanand,实际的输出是 BI

assume I select Aztec Auto Ltd then expected output from servlet is same right. But output is Aztec. similarly, if I select BI Sanand, the actual output that comes is BI

有人可以帮忙吗

推荐答案

您需要引用值.

<option value="<%=locationDO.getLocationName().trim()%>">

空格即HTML属性分隔符.当您通过右键单击页面 > 查看源代码检查生成的 HTML 时,带有一点体面语法高亮器的浏览器已经提示了它.

The space is namely a HTML attribute separator. A browser with a bit decent syntax highlighter would already have hinted it when you have checked the generated HTML by rightclick page > View Source.

<option value=Aztec Auto Ltd>

对比

<option value="Aztec Auto Ltd">

这篇关于请求参数值在包含空格时被截断为第一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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