Presentation is loading. Please wait.

Presentation is loading. Please wait.

MC365 Application Servers: Java Server Pages (JSP’s) and Session Management.

Similar presentations


Presentation on theme: "MC365 Application Servers: Java Server Pages (JSP’s) and Session Management."— Presentation transcript:

1 MC365 Application Servers: Java Server Pages (JSP’s) and Session Management

2 Today We Will Cover: What a jsp is Configuring Tomcat to use your jsp Using beans to communicate between servlets and jsp’s. Debugging jsp’s 3 main ways to manage sessions

3 What is a JSP? JSP stands for Java Server Page JSP’s are simply an HTML document combined with java code. –Note: The app server actually treats the jsp as a servlet and compiles the code into a class file before it executes it. This is transparent to the developer. Their purpose is to allow for dynamic web content. Servlets and JSP’s communicate and pass information back and forth using parameters.

4 Example of a simple JSP To see what a jsp looks like go to: http://www2.bc.edu/~bernier/MC365/Lecture Notes/basic.jsp http://www2.bc.edu/~bernier/MC365/Lecture Notes/basic.jsp

5 Example of a servlet calling a JSP To see an example of how a jsp is called in a servlet. http://www2.bc.edu/~bernier/MC365/Lecture Notes/ServletToJSP.java http://www2.bc.edu/~bernier/MC365/Lecture Notes/ServletToJSP.java

6 Configuring Tomcat to use JSP’s You can put jsp’s anywhere under the document base for your application. –Some developers like to put them in the document root directory. –Others like to keep them together under a jsp directory. Wherever you put them, you need to reference that path when you call a jsp from the servlet.

7 Using Beans in JSP’s Beans are often the most efficient way to pass a large number of parameters from a servlet to a jsp. –In Tomcat, when you use beans in jsp’s, they must be in a package.. Here is an example of a servlet accepting a parameter from one jsp and using a bean to pass a number of parameters to another jsp: http://www2.bc.edu/~bernier/MC365/Lecture Notes/SimpleJSPServlet.java http://www2.bc.edu/~bernier/MC365/Lecture Notes/SimpleJSPBean.java http://www2.bc.edu/~bernier/MC365/Lecture Notes/AppLogger.java http://www2.bc.edu/~bernier/MC365/Lecture Notes/input.jsp http://www2.bc.edu/~bernier/MC365/Lecture Notes/SimpleJSPServlet.java http://www2.bc.edu/~bernier/MC365/Lecture Notes/SimpleJSPBean.java http://www2.bc.edu/~bernier/MC365/Lecture Notes/AppLogger.java http://www2.bc.edu/~bernier/MC365/Lecture Notes/input.jsp http://www2.bc.edu/~bernier/MC365/Lecture Notes/simple.jsp

8 Debugging JSP’s So how do you debug a problem in a jsp. Because jsp’s get compiled into servlets, you can sometimes get the error HTTP Status Error 500 for a jsp. To debug a problem in a jsp: –Use loggers to write messages just like in servlets. –Another trick is to take out chunks of code and start with the basics. Test the jsp. Keep adding code back in and testing until you come across the error. At that point you will have identified where exactly the problem code lies.

9 3 Main Ways to Maintain Sessions using session object –you don’t want to use this too often –puts too much of a strain on server resources using cookies –you don’t want to use this too often either –users may have cookies turned off in browser passing parms in request object between a servlets and jsp’s


Download ppt "MC365 Application Servers: Java Server Pages (JSP’s) and Session Management."

Similar presentations


Ads by Google