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

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

问题描述

我对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天全站免登陆