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

2019-03-02 17:53发布

问题:

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??

回答1:

Put double quotes around the value like this -

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

HTML uses space to separate different attributes/tags.



回答2:

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


回答3:

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?



标签: html jsp input