Set - 2

Question 11 :

How can I declare methods within my JSP page?

Answer :

You can declare methods for use within your JSP page as declarations. The methods can then be invoked within any other methods you declare, or within JSP scriptlets and expressions.
Do note that you do not have direct access to any of the JSP implicit objects like request, response, session and so forth from within JSP methods. However, you should be able to pass any of the implicit JSP variables as parameters to the methods you declare.
For example:
Another Example:
file1.jsp:
file2.jsp

<%test(out);% >


Question 12 :

Can I stop JSP execution while in the midst of processing a request?

Answer :

Yes. Preemptive termination of request processing on an error condition is a good way to maximize the throughput of a high-volume JSP engine. The trick (assuming Java is your scripting language) is to use the return statement when you want to terminate further processing.


Question 13 :

Can a JSP page process HTML FORM data?

Answer :

Yes. However, unlike Servlet, you are not required to implement HTTP-protocol specific methods like doGet() or doPost() within your JSP page. You can obtain the data for the FORM input elements via the request implicit object within a scriptlet or expression as.


Question 14 :

Is there a way to reference the "this" variable within a JSP page?

Answer :

Yes, there is. Under JSP 1.0, the page implicit object is equivalent to "this", and returns a reference to the Servlet generated by the JSP page.


Question 15 :

How do you pass control from one JSP page to another?

Answer :

Use the following ways to pass control of a request from one servlet to another or one jsp to another.
The RequestDispatcher object 's forward method to pass the control.
The response.sendRedirect method