문제

I want to display the error message in two lines in Struts2

User Name is not valid
Password is not valid

and my property is:

username.password.errrorMsg: User Name is not valid \n Password is not valid.

I added \n but its displaying in single line.

Can you suggest to display in two lines?

도움이 되었습니까?

해결책

If you use a message format then \n symbol add a new line character. If you want to display this message with actionerror or actionmessage tags you need to use <br> and let it not escape. For example

<s:actionmessage escape="false"/> 

다른 팁

Because new line/breaking character depends on where do you use/show message it is better to use different messages for that.

invalid.userName = User Name is not valid
invalid.password = Password is not valid

In this way you can use them separately in case you want to show specific message and display them as you want.


If you displaying them in HTML/JSP using S2 <s:text> tag then <br/> should work. But several tags are escaping HTML so for example to use this kind of message in <s:property> with getText() you need to set escapeHTML attribute to false.

Probably < br/> (without the space between < and b :P), as the output format is html.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top