What is the equivalent of die() in Spring?

二次信任 提交于 2021-02-11 13:00:17

问题


In PHP there is the die("some message"); to write output and stop the execution of the script. So is there an equivalent in Spring mvc ( in Controller and in the JSP ) ?


回答1:


There is no reason to have something like die() in Java/JSPs. JSPs should be used as a pure view technology. It should just generate HTML. Not try to access a database, read files or whatnot. That is the job of a controller, written in Java

Use System.exit(0); to exit the java code.

Keep a note this will stop the JVM instance which is currently running.

If you want to come out of a method use return or throw exception to showcase error condition.



来源:https://stackoverflow.com/questions/39158564/what-is-the-equivalent-of-die-in-spring

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!