【发布时间】:2023-03-05 06:01:01
【问题描述】:
我需要在自定义Exception 抛出的消息之间换行。
我正在使用 Struts 2 addActionError(),错误消息将显示在 JSP 上。
这是我的 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");
}
所以我需要在浏览器的第一行显示"We are getting problem with connecting our Antivirus Server",在下一行显示"Please try again after some time"。
我尝试了\n、<br> 和&ltbr&gt,但它们不起作用。
【问题讨论】:
-
异常消息不应包含任何专用于显示的格式信息。我什至建议不要将异常消息用作 GUI 消息。让你的 GUI 处理异常(也许让它读取
exception.getMessage())让它显示正确的失败消息。解析异常消息和组装 GUI 消息只是 GUI 的职责。 -
你在哪里使用
addAction?这个jsp怎么显示? -
以上代码在 Util 类中,我从 Action 类调用并在 jsp 中以下列方式使用它
标签: java jsp exception error-handling struts2