Java
  Home arrow Java arrow Page 2 - What Can JSP Do For Me?
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
JAVA

What Can JSP Do For Me?
By: Ben Shepherd
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 13
    2003-07-28

    Table of Contents:
  • What Can JSP Do For Me?
  • Getting Up to Speed with JSP
  • Simple JSP Files
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    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:

    Below the closure of the last Context tab:

    </Context>

    and above the closure of the following tabs:

        </Host>
      </Engine>
    </Service>


    add the following Context element:

    <Context path="/yadayada" docBase="yadayada" debug="1" reloadable="true"/>

    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:

    <servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
    <param-name>logVerbosityLevel</param-name>
    <param-value>WARNING</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
    </servlet>

    as well as 

    <!-- 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.

    More Java Articles
    More By Ben Shepherd


     

    JAVA ARTICLES

    - Deploying Multiple Java Applets as One
    - Deploying Java Applets
    - Understanding Deployment Frameworks
    - Database Programming in Java Using JDBC
    - Extension Interfaces and SAX
    - Entities, Handlers and SAX
    - Advanced SAX
    - Conversions and Java Print Streams
    - Formatters and Java Print Streams
    - Java Print Streams
    - Wildcards, Arrays, and Generics in Java
    - Wildcards and Generic Methods in Java
    - Finishing the Project: Java Web Development ...
    - Generics and Limitations in Java
    - Getting Started with Java Web Development in...







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek