jsp - 从 java 字符串设置输入标签 (html) 的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16029843/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 07:35:29  来源:igfitidea点击:

jsp - set value of input tag (html) from a java string

htmljspinput

提问by user2285089

I'm facing a strange problem here. The situation is like this:

我在这里面临一个奇怪的问题。情况是这样的:

I'm trying to set a value for an inputtag from a java string:

我正在尝试input从 java 字符串为标签设置一个值:

   <input type="text" name="line" value=<%=line%>  ></input>

line = "this is my new line"

the result is that valueis getting only the first word("this") and not the whole string.

结果是value只获取第一个单词(“this”)而不是整个字符串。

anyone knows why or how to make it right??

有谁知道为什么或如何使它正确?

回答by Bhushan Bhangale

Put double quotes around the value like this -

像这样在值周围加上双引号 -

<input type="text" name="line" value="<%=line%>"></input>

HTML uses space to separate different attributes/tags.

HTML 使用空格来分隔不同的属性/标签。

回答by Ashok Damani

<input type="text" name="line" value="<%=line%>"></input>

回答by Suresh Atta

As everybody said use double quotes

正如大家所说的使用双引号

<input type="text" name="line" value=<%=line%>  ></input>

The above line is only for correct your line and,if possible please do not use scriplets.Those are expired.

以上行仅用于更正您的行,如果可能,请不要使用脚本。那些已过期。

Please go through this How to avoid Java code in JSP files?

请通过这个如何避免 JSP 文件中的 Java 代码?