1 / 9

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

MC365 Application Servers: Java Server Pages (JSP’s) and Session Management. 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. What is a JSP?.

salali
Download Presentation

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

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. MC365Application Servers:Java Server Pages (JSP’s)andSession 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

  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

  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.javahttp://www2.bc.edu/~bernier/MC365/Lecture Notes/SimpleJSPBean.javahttp://www2.bc.edu/~bernier/MC365/Lecture Notes/AppLogger.javahttp://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

More Related