I have a list of bean objects passed into my JSP page, and one of them is a comment field. This field may contain newlines, and I want to replace them with semicolons using JSTL, so that the field can be displayed in a text input. I have found one solution, but it's not very elegant. I'll post below as a possibility.
相关问题
- how to split a list into a given number of sub-lis
- Generate string from integer with arbitrary base i
- Replacing more than n consecutive values in Pandas
- Converting a string array to a byte array
- How to convert a string to a byte array which is c
相关文章
- jsp里面的画布功能,为什么会出错?求大佬找下问题
- JSP String formatting Truncate
- Selecting only the first few characters in a strin
- Python: print in two columns
- Forward request from servlet to jsp
- extending c++ string member functions
- Google app engine datastore string encoding proble
- Comparing string and boolean in Expression languag
This does not work for me:
This does:
If what you really need is a \n symbol you can use the advice from here:
or
This includes the new line in your string literal.
This is similar to the accepted answer (because it is using Java to represent the newline rather than EL) but here the <c:set/> element is used to set the attribute:
The following snippet also works, but the second line of the <c:set/> element cannot be indented (and may look uglier):
Here is a solution I found. It doesn't seem very elegant, though:
This is a valid solution for the JSP EL:
You could create your own JSP function. http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags6.html
This is roughly what you need to do.
Create a tag library descriptor file
/src/META-INF/sf.tld
Create a Java class for the functions logic.
com.stackoverflow.web.tag.function.TagUtils
In your JSP you can access your function in the following way.