Technologies for Projects
R. Alexander Milowski
milowski at sims.berkeley.edu
#1
Categories
J2EE & J2EE Servlet Components
JSP tricks
Smallx Pipelines
#2
Create a Web Application Project
Just create a web application project in Netbeans for your final project.
This will allow you to create war files/etc.
You'll need to adjust the war file to work outside netbeans' Tomcat.
Just add the following to the build.xml:
<target name="-post-dist"> <mkdir dir="${dist.dir}/deploy/tmp"/> <unjar src="${dist.war}" dest="${dist.dir}/deploy/tmp"/> <delete file="${dist.dir}/deploy/tmp/META-INF/context.xml"/> <copy file="${web.docbase.dir}/META-INF/context.xml" todir="${dist.dir}/deploy/tmp/META-INF"/> <jar basedir="${dist.dir}/deploy/tmp" destfile="${dist.dir}/deploy/${war.name}" includes="**"/> <delete dir="${dist.dir}/deploy/tmp"/> </target>
This creates the same war file in a 'deploy' sub-directory which can be used outside of netbeans.
#3
J2EE Servlet Container Components
You can use any J2EE Servlet component you wish.
Just copy the supporting jar files into WEB-INF/lib
You'll have to add the right things to you WEB-INF/web.xml as documented by the component.
#4
The urlrewrite Component
This component acts as a servlet filter and redirects requests.
It matches the request based on a perl-like regular expression.
It then forwards it as you've specified.
The jar files and documentation are available at http://urlrewrite.dev.java.net
The jar files are also in the smallx samples I'll be distributing.
Here is an example configuration:
Add this to the WEB-INF/web.xml file:
<filter> <filter-name>UrlRewriteFilter</filter-name> <filter-class>org.tuckey.web.filters.urlrewrite.UrlRewriteFilter</filter-class> <!-- uncomment me to turn on debugging <init-param> <param-name>logLevel</param-name> <param-value>DEBUG</param-value> </init-param> --> <init-param> <param-name>confReloadCheckInterval</param-name> <param-value>60</param-value> </init-param> </filter> <filter-mapping> <filter-name>UrlRewriteFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
The WEB-INF/urlrewrite.xml file:
<!DOCTYPE urlrewrite PUBLIC "-//tuckey.org//DTD UrlRewrite 2.0//EN" "urlrewrite.dtd"> <urlrewrite> <rule> <from>(.+)/site.css$</from> <to>/site.css</to> </rule> <rule> <from>/(.+)/mydoc.xml</from> <to>/mydoc.xml?view=$1</to> </rule> </urlrewrite>
#5
Xerces Jar Files
You'll need the 'resolver.jar' and 'xercesImpl.jar' for any of the Xerces samples.
You'll find a version of this in the JAXP samples on the lecture from 2/15
I built this version and can update them if you have problems.
You can also download them from www.apache.org.
#6
JSP Files
By default, .jsp extensions will be recognized as JSP files.
Netbeans will understand this, let you create them, and do syntax highlighting.
You can use all the JAXP examples I've given you inside these JSP files.
You'll have to put any supporting jar files for your code in the WEB-INF/lib directory.
If you write Java code, you can put the packages under "Source Packages" and they'll build appropriately inside Netbeans.
#7
What you can do with JSP files
Implement a web service.
Handle web forms.
Style content using XSLT.
Access databases/etc. via tag libraries.
#8
Implementing a Web Service using JSP
In the 2/15 Lecture, I showed an example of this.
That code is available on the class web page.
JSP's can handle input/output of XML as easily as it handles forms.
#9
XSLT Filters via JAXP
In the 2/3 Lecture I showed how to setup an XSLT filter.
You used this in the third assignment.
You can use the jar file from that assignment but the code is in the jaxp.zip available from the 2/15 lecture.
#10
smallx Pipelines
You can use smallx pipelines to implement more complicated web services.
It will also allow you to interface with other web services quite easily.
You can also use it inside JSP in several different ways depending on your application.
The netbeans module will let you run the pipelines inside netbeans just like you do XSLT.
You'll need a distribution of the smallx examples to do this inside a web applications.
#11
smallx Examples
I've made available a version of the smallx pipelines and servlet integration.
In the 'xml' directory is the supporting XML technology for pipelines and standalone examples.
In the 'server' directory is the supporting J2EE integration for pipelines and example web applications.
Each example is a netbeans project that you can open.
The examples are as follows:
xml/examples/ - example pipelines and components
server/webapps/XMLPost - an example JSP application for posting XML content to web services.
server/webapps/bart-service - The bart.gov screen-scrapping example web service.
server/webapps/mystuff - The example front-end to bart-service.
server/webapps/rss-feed-service - An RSS feed converter that turns the descriptions into XML.
server/webapps/rss-feed - An example front-end to the RSS feed service.
server/webapps/contacts-service - A contacts database web service.
server/webapps/contacts - an example front-end to the contacts web service that supports mobile devices.
server/webapps/pipeapp - an extremely simple test of the pipe integration.
server/webapps/xsltapp - an extremely simple test of the XSLT filter.