Friday, April 1, 2011

JSP Scripting Elements

Scripting Elements are basically used to add contents to the HTML page dynamically.
Lets you add java code inside the HTML/JSP.

1) JSP Comments
-FORMAT <!-- -->
- used to comments for user information.

2) JSP Expressions
- used to insert dynamic results to the output page.
- FORMAT - <%= expression %>
- they are printed directly to the output page.
- e.g. Thanks for ordering <%= request.getParameter("title") %>
- e.g. Current time: <%= new java.util.Date() %>
- XML SYNTAX - Java Expression

3) JSP Scriptlets
- used to insert java code into the method that handles request for the page.
- FORMAT - <% code %>
- they are inserted into the _jspservice(called by service) method of the servlet.
- they have access to implicit objects automatically.
- e.g. <% String q = request.getQueryString(); out.println("GET data: " + q);%>
- they can be used for setting response headers and status codes, invoking side effects such as writing to the server log or updating a database, or executing code that contains loops, conditionals, or other complex constructs.

4) JSP Declaraions
- used to add methods and field declarations to the servlet that corresponds to the JSP page.
- FORMAT - <%! Java Code %>
- they are inserted to the main body of the servlet class, outside the _jspService() and called by service to process the request.
- implicit objects wont be accessible within declarations.

No comments:

Post a Comment