JDBC, EJB, Java IDL, JNDI, JTS, Servlets, the list goes on. There is limitless possibilities that arise when one is developing web applications using the JSP technology. Read more to get a glimpse at how to develop JSP pages using Tomcat.
What Can JSP Do For Me? - Getting Up to Speed with JSP (Page 2 of 4 )
What we need to do is setup our system so we can build web applications using JSP technology. It would be a great idea to install the latest Tomcat Servlet/JSP Container, if you haven’t already done this.
To get Tomcat, simply go to http://jakarta.apache.org/site/binindex.html and locate the newest version. I decided to go with standard v4.1.24, which includes all optional libraries and an XML parser (Xerces 2.0.1), and can be run on JDK 1.2+. Once you’ve downloaded it, unzip it to the C: directory. I’ll choose the C: anyway.
Now, to set the environment variables, since I’m on Windows XP, it will be the same for Windows 2000. Go to the System folder in the Control Panel. Select the Advanced tab, and click on the “Environment Variables”, then select “System Variables”. Click on the “New” button to add System variables.
Add the following entries into the System registry:
Variable name = CATALINA_HOME Variable value = C:\jakata-tomcat-4.1.24 and Variable name = JAVA_HOME Variable value = C:\j2sdk1.4.1_01
Now, when you double click on C:\jakarta-tomcat-4.1.24\bin\startup.bat to start Tomcat, the registry will be ready for Tomcat’s requests. To stop Tomcat, simply double click on C:\jakarta-tomcat-4.1.24\bin\shutdown.bat.
Now Tomcat is setup, I go through JSP. The separation of presentation from implementation is one of the key features of JSP. This allows a team, consisting of programmers and page designers, to work independently from each other and produce web applications in a more efficient manner. No longer does a team need to be made up of multi-skilled employees. The team of specialists that can handle their allocated tasks quickly can do the work needed. This saves both time and money.
OK. Enough with the small talk and let us get into some code to demonstrate how JSP would handle a simple request of an IP address. Locate the directory, C:\jakarta-tomcat-4.1.24\ C:\jakarta-tomcat-4.1.24\webapps. This is the folder that you will use to store your JSP files. Create a folder and name it “yadayada”.
Since you have created our new folder, open C:\jakarta-tomcat-4.1.24\conf\server.xml and towards the bottom of the file:
Now, you need to restart Tomcat. Every time there is a change with the hierarchy you must restart Tomcat.
How are JSP files Processed?
A lot of server today process JSP files by taking the JSP requests and forwarding them to a JSP processor servlet. Since, we are using Tomcat. You'll notice in C:\jakarta-tomcat-4.1.24\conf\web.xml, that the following can be sited:
<!-- The mapping for the JSP servlet --> <servlet-mapping> <servlet-name>jsp</servlet-name> <url-pattern>*.jsp</url-pattern> </servlet-mapping>
This means that requests that come from a url that ends with "*.jsp", that jsp files are mapped as a jsp servlet, which are forwarded to the org.apache.jasper.servlet.JspServlet servlet.
XML and JSP
XML is renowned for its proficiency is data representation. It is hierarchal as opposed to relational, so there is no need to learn normalisation. To use JSP with XML is fairly simple. JSP may use SAX and DOM to parse and collect data from a XML file. You may wish to place the data into a java.util.List object so you can quickly retrieve a needed result. To tidy JSP output, one may use a XSL processor to transform the XML file into HTML code. Not only that, you may convert XML into a variety of other formats like pdf documents using the Java API.