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

2019-03-02 17:28发布

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

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

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

line = "this is my new line"

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

anyone knows why or how to make it right??

标签: html jsp input
3条回答
疯言疯语
2楼-- · 2019-03-02 18:05

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?

查看更多
手持菜刀,她持情操
3楼-- · 2019-03-02 18:10
<input type="text" name="line" value="<%=line%>"></input>
查看更多
看我几分像从前
4楼-- · 2019-03-02 18:25

Put double quotes around the value like this -

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

HTML uses space to separate different attributes/tags.

查看更多
登录 后发表回答