简体   繁体   English

Java中自定义异常抛出的消息中的断行

[英]Break line in message thrown by custom Exception in Java

I need to break line between my message thrown by custom Exception .我需要在自定义Exception抛出的消息之间换行。

I'm using Struts 2 addActionError() and the error message will be displayed on JSP.我正在使用 Struts 2 addActionError()并且错误消息将显示在 JSP 上。

So here is my Java code:所以这是我的Java代码:

if (result_Of_Scan.equals("ERROR")) {
    throw new AdserverException("We are getting problem with connecting our " 
                    + "Antivirus Server! Please try  again after some time");
}

So I need to show "We are getting problem with connecting our Antivirus Server" on first line and "Please try again after some time" on next line on the browser.因此,我需要在浏览器的第一行显示"We are getting problem with connecting our Antivirus Server" ,并在下一行显示"Please try again after some time"

I have tried \\n , <br> and &ltbr&gt but they are not working.我试过\\n<br>&ltbr&gt但它们不起作用。

To display the message on the new line in JSP you should use <br> .要在 JSP 中的新行上显示消息,您应该使用<br> It didn't display on the new line when you have tried it because <s:actionerror> by default escapes html.当您尝试它时,它没有显示在新行上,因为<s:actionerror>默认情况下会转义 html。 You should use escape="false" attribute to change the output to allow rendering html.您应该使用escape="false"属性来更改输出以允许呈现 html。

<s:if test="hasActionErrors()"> <div class="alert_msg alert"> <s:actionerror escape="false"/> </div> </s:if>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM