JSP文件中嵌入java代码
我想问你关于编程方面的问题,我通过以下方式将java代码嵌入到JSP页面中 <% Java代码
%>
在java代码中,我实例化对象并使用流程控制,例如if和for。我的问题是: 本例中的java代码是在逻辑层还是表示层执行的?如果我们从设计角度来看该程序,
请提前致谢
I want to ask you about programming aspect , I embedded java code inside JSP page in the following way
<%
Java code
%>
In java code I instantiate objects and use flow control such as if and for. My question is:
Is the java code in this case performed in the logic tier or Presentation tier? If we look at the program from the design view
thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每个 jsp 页面都会被 servlet 容器(例如 Tomcat、Jetty 等)转换为 servlet,根据定义,servlet 容器是您的表示层。您的代码块包含在同一个 servlet 中,因此是同一层的一部分。
然而,层级只是一个概念,没有硬性界限。例如,在 jsp 中实例化的某些对象中,您执行的服务逻辑可能会被解释为不同的层。
作为一般规则,最好将 jsp 中执行的与演示文稿无关的所有逻辑提取到单独的服务中,然后可以从 servlet/jsp 中调用。使用大量代码块通常表明是时候重构和分离它了。
Every jsp page will be transformed into a servlet by the servlet container (eg. Tomcat, Jetty etc.) which by definition is your presentation tier. Your code blocks are contained within the same servlet and are thus part of the same tier.
Tiers however are a concept and do not have hard boundries. It might for example be that in some of the objects you instantiate in your jsp you execute service logic that could be interpited as a different tier.
As a general rule it is a good idea to pull all logic executed in your jsp's that do not have anything to do with your presentation out into seperate services you then can call from within your servlets/jsp's. Using a lot of code blocks is generally a sign it is time to refactor and seperate it out.