Search code examples
web-applicationsprogramming-languages

java code embedded in JSP file


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


Solution

  • 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.