2014-01-20 65 views
3

我想在兩線在Struts2插入在Struts2 messages.properties新線

User Name is not valid 
Password is not valid 

顯示錯誤消息,我的屬性是:

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

我加\n但其在單顯示線。

你能建議以兩行顯示嗎?

+0

不這樣做。使用單獨的消息。 –

+0

感謝Aleksandr,我使用了分離的消息,我可以知道爲什麼我們需要使用單獨的消息嗎? – sree

回答

5

如果使用消息格式,則使用\n符號添加一個新的行字符。如果你想顯示actionerroractionmessage標籤這個消息你需要使用<br>並讓它不能逃脫。例如

<s:actionmessage escape="false"/> 
+1

感謝羅馬,我只是將
放在屬性文件中並使用在jsp中,它的工作非常感謝 - – sree

0

可能<(沒有<和b:P之間的空格),因爲輸出格式爲html。

+0

它不工作Brierson :( – sree

+0

你怎麼顯示錯誤消息 – Brierson

+0

username.password.errrorMsg:用戶名無效
密碼無效 它顯示:用戶名無效
密碼無效 – sree

2

因爲換行/打破字符取決於你在哪裏使用/顯示消息,最好使用不同的消息。

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

通過這種方式,你可以分開使用的情況下,你想顯示具體的消息,只要你想顯示他們。


如果您在HTML/JSP使用S2 <s:text>標籤然後<br/>應該工作顯示它們。但是有幾個標籤正在轉義HTML,例如在<s:property>getText()中使用這種消息,則需要將escapeHTML屬性設置爲false。

+0

好吧,但我添加動作錯誤,如 addActionError(getText(「usernam e.password.errrorMsg「)) – sree

+0

@sree:正如我所說有幾個S2標籤可以轉義HTML,」「就是其中之一。您可以使用'escape'屬性來控制是否轉義消息。 –

+0

感謝Aleksandr,我只是把
放在屬性文件中,並且在jsp中使用了,它的工作非常感謝 – sree