JavaBeat
Stripes Home Articles Tutorials Java Interview Questions & FAQs Java QnA Code Junction

1. Stripes WebFramework- Introduction
2. Requirements
3. Configuring Stripes
4. My First Stripe
5. The ActionBean
6. Adding Validation
7. Adding another Operation

Configuring Stripes

Stripes is designed to require as little configuration as possible. To get it up and running you simply need to configure the Stripes Filter and the Stripes Dispatcher Servlet in your web application's web.xml. A pretty standard configuration would look like this:


web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
version="2.4">

<filter>
<display-name>Stripes Filter</display-name>
<filter-name>StripesFilter</filter-name>
<filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>StripesFilter</filter-name>
<url-pattern>*.jsp</url-pattern>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<filter-mapping>
<filter-name>StripesFilter</filter-name>
<servlet-name>StripesDispatcher</servlet-name>
<dispatcher>REQUEST</dispatcher>
</filter-mapping>

<servlet>
<servlet-name>StripesDispatcher</servlet-name>
<servlet-class>net.sourceforge.stripes.controller.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>StripesDispatcher</servlet-name>
<url-pattern>*.action</url-pattern>
</servlet-mapping>
</web-app>

Next you'll need to drop stripes.jar into your classpath, usually in your /WEB-INF/lib directory. This is the only compile-time dependency for developing with Stripes. For deploying and running Stripes you will also need to copy the following library files supplied with Stripes into your classpath:

  • commons-logging.jar (1.1) - Apache Commons Logging is used to provide an implementation agnostic logging interface.
  • cos.jar - the com.oreilly.servlets package, courtesy of Jason Hunter, is used to manage multi-part file uploads as part of form submissions

The above libraries are all supplied in the Stripes distribution, and have been tested with Stripes. More recent versions may work, but your mileage may vary.

In addition, it's very helpful to be able to see the logging output of Stripes. To do this you'll need to supply either a working Log4J setup, or another Commons Logging compatible setup. The Log4J jar, log4j-1.2.9.jar, is distributed with Stripes. Sample Commons Logging and Log4J configuration files follow:

commons-logging.properties
org.apache.commons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

log4j.properties

### direct log messages to stdout ###
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.Target=System.out
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### direct messages to file ###
log4j.appender.file=org.apache.log4j.FileAppender
log4j.appender.file.File=/tmp/stripes.log
log4j.appender.file.layout=org.apache.log4j.PatternLayout
log4j.appender.file.layout.ConversionPattern=%d{ABSOLUTE} %5p %c{1}:%L - %m%n

### set log levels - for more verbose logging change 'info' to 'debug' ###
log4j.rootLogger=INFO, stdout, file
log4j.logger.net.sourceforge.stripes=DEBUG

The logging configuration files need to be placed in your classpath, for example in /WEB-INF/classes.

The last piece to put in place is the StripesResources.properties; you'll want to copy that to /WEB-INF/classes for now. StripesResources.properties is used (by default) to lookup error messages both for Stripes' built in validations, and for any validation done in ActionBeans, and it has to be available in the Classpath. An example fragment of the file follows:

Example StripesResources.properties

# Validation error messages used by Stripes' built in type converters converter.number.invalidNumber=The value ({1}) entered in field {0} must be a valid number converter.byte.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} converter.short.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} converter.integer.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} converter.float.outOfRange=The value ({1}) entered in field {0} was out of the range {2} to {3} converter.enum.notAnEnumeratedValue=The value "{1}" is not a valid value for field {0} converter.date.invalidDate=The value ({1}) entered in field {0} must be a valid date converter.email.invalidEmail=The value ({1}) entered is not a valid email address



Sponsors
Webmaster Hosting Forum
Java Jobs
MyVideoLib
India News
Internet Advances
Latest QnA
SCJD Tips
When we start a thread by applying start() method on it ,how does it knows that to execute run()method?
About Wrapper class in Java
How to configure weblogic 7.0 in MyEclipse?
Static Block and Static Initializer in Java

JavaBeat Media (2004-2008), India
javabeat | planetoss | links directory | advertise
Copyright (2004 - 2008), JavaBeat