What is the difference between <%! %> and <% %> in JSP?

混江龙づ霸主 提交于 2019-11-30 08:33:51

<%! %> are JSP Declaration tags while <% %> are JSP Scriptlet tags.

Any code you put in scriptlets gets put in the JSPs _jspService() method when it's compiled (the analogue of a Servlet's doGet, doPost,... methods). This is what you'd usually write your Java code in.

But what if you want to declare new methods in your JSP class or declare instance variables? That's when you'd use the declaration tags. Any thing you put in there gets put into the JSP, outside of the _jspService() method.

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