Monday 26 November 2012

Advanced Java Programming JSP

Advanced Java Programming Unit 4
 JSP Structure
4.1 Introduction Objectivies
4.2 What is needed to write JSP based web application? Self Assessment Questions
 4.3 How does JSP look?
4.4 How to test a JSP?
4.5 Summary
4.6 Terminal Questions

 4.1 Introduction JavaServer pages are on the whole, text files that combine standard HTML and new scripting tags. JSPs look like HTML, but they get compiled into Java Servlets the first time they are invoked. The resulting servlet is a combination of the HTML from the JSP file and embedded dynamic content specified by the new tags. That is not to say that JSPs must contain HTML. Some of them will contain only Java code; this is particularly useful when the JSP is responsible for a particular task like maintaining application flow. Objectives In this chapter, you will learn about the:  Life Cycle of JSP  JSP Structure  Writing JSP Program

4.2 What is needed to write JSP based web application? As you will come to know in a short time, programming with JSP will need a thorough knowledge of how servlets are written and executed as the code Advanced Java Programming Unit 4 Sikkim Manipal University Page No. 99 segments inserted in a JSP are mostly Servlet code. If you have already written some ASP programs you may find it easy to work with JSP as there are so many similarities although they are 2 different technologies. To write a JSP code you require an editor. To test the JSPs you need a JSP engine. So this material considers the Java Web Server to the JSP engine. This is the same web server that we considered for testing the Java Servlets. Self Assessment Questions 1. What is the use of JSP?

 4.3 How does JSP look? Before considering more technical details regarding JSP, let us see how a JSP file looks and what its static parts are and what its dynamics parts are: Consider the HelloWorld.jsp below 1. 2. 3. 4. 5. 6. 7.

8. <% out.println(“Hello World!”); %> 9.

10.
11. As you can see a JSP page looks almost like a simple HTML file. In the above HelloWorld.jsp line number 8 is the one accounting for the dynamoc Advanced Java Programming Unit 4 Sikkim Manipal University Page No. 100 content. All of the rest lines are static HTML content. If you observe line 8 carefully, you can notice that the written code resembles servlet code in some way.

4.4 How to test a JSP? Once a JSP is written next question is how do you test it? To test JSP we are going to use Java Web Server. The steps are as following:  Copy the HelloWorld.jsp to c:\JavaWebServer2.0\public_html directory as it is the document root of the Java Web Server . (Assuming that the Java Web Server is installed in c:\)  Now start the Java Web Server’s web service.  Open your browser window.  Now in the address bar type in an address as http://IPAddress:8080/HelloWorld.jsp, where IP address of your machine.  You should be able to see the output as shown below. Fig. 4.4.1: JSP Output Advanced Java Programming Unit 4 Sikkim Manipal University Page No. 101

 4.5 Summary This section has covered most of the nuts and bolts required in effective JSP authoring. The different kinds of tags, their syntax, and usage have been covered. To get the feel of how powerful are JSPs, the reader is encouraged to try everything out by running actual examples.

4.6 Terminal Questions 

What is JSP?

 Explain With an example? 

What are the uses of JSP?

No comments:

Post a Comment