Introduction to struts 2 intercepting string code

During development, we often encounter the problem that the string is too long and needs to be intercepted and displayed properly. In fact, there are several implementation methods:

・ after background interception, it will be returned to the page for display

・ implemented with tags or code on the page

・ it is not recommended to use script in the foreground

・ through style control, add overflow: ellipse and other implementations. This method is also not recommended

・ other methods

So how to use the struts 2 tag to intercept strings? There are different opinions on this issue on the Internet, and some people say it can't be realized at all. In fact, the implementation method is very simple: first, you must use < s: set > to save the obtained string into a variable, and take STR attribute as an example to directly obtain < s: set name = "STR" value = "list" > < / s: set >, when obtaining from the set: < s: iterator value = "set" >< s:set name="str" value="str"> ......................... then judge the interception code:

In addition, there is a simpler method. Instead of set, you can directly use the variable name:

Speaking of this, basically your interception problem can be solved. However, this method seems to have some problems with strings containing HTML tags. It will also intercept HTML tags, resulting in page deformation and even "disfigurement" due to tag mismatch. In fact, we all know the principle of solving this problem, that is, we need to filter out the HTML tag in the note string in advance, and check the tag description of struts 2. It seems that there is no such method, alas. So I searched the Internet and found the solution of only one piece of code: the method of intercepting string with HTML tag by struts 2

It can run and learn a little more. Text is a variable. The function of this tag is to remove all HTML tags from the obtained value and intercept the first 77 characters. The following escape ='false 'means that the HTML tag is not encoded. So far, the problem is solved, applaud! From this usage, we can know that all methods of Java string class are supported on the struts 2 tag. The usage is very convenient. This article will play a role in attracting jade.

summary

The above is all about the introduction of struts 2 intercepting string code in this article. For more information, please refer to: solutions to the problem that struts and servlet cannot coexist, analysis of struts 2 modifying upload file size limit, struts 2 development process and detailed configuration, etc. welcome to browse other topics of this site, and thank friends for their support for this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>