- GUI
- Windows API tutorial
- Introduction to Windows API
- Windows API main functions
- System functions in Windows API
- Strings in Windows API
- Date & time in Windows API
- A window in Windows API
- First steps in UI
- Windows API menus
- Windows API dialogs
- Windows API controls I
- Windows API controls II
- Windows API controls III
- Advanced controls in Windows API
- Custom controls in Windows API
- The GDI in Windows API
- PyQt4 tutorial
- PyQt5 tutorial
- Qt4 tutorial
- Introduction to Qt4 toolkit
- Qt4 utility classes
- Strings in Qt4
- Date and time in Qt4
- Working with files and directories in Qt4
- First programs in Qt4
- Menus and toolbars in Qt4
- Layout management in Qt4
- Events and signals in Qt4
- Qt4 Widgets
- Qt4 Widgets II
- Painting in Qt4
- Custom widget in Qt4
- The Breakout game in Qt4
- Qt5 tutorial
- Introduction to Qt5 toolkit
- Strings in Qt5
- Date and time in Qt5
- Containers in Qt5
- Working with files and directories in Qt5
- First programs in Qt5
- Menus and toolbars in Qt5
- Layout management in Qt5
- Events and signals in Qt5
- Qt5 Widgets
- Qt5 Widgets II
- Painting in Qt5
- Custom widget in Qt5
- Snake in Qt5
- The Breakout game in Qt5
- PySide tutorial
- Tkinter tutorial
- Tcl/Tk tutorial
- Qt Quick tutorial
- Java Swing tutorial
- JavaFX tutorial
- Java SWT tutorial
- wxWidgets tutorial
- Introduction to wxWidgets
- wxWidgets helper classes
- First programs in wxWidgets
- Menus and toolbars in wxWidgets
- Layout management in wxWidgets
- Events in wxWidgets
- Dialogs in wxWidgets
- wxWidgets widgets
- wxWidgets widgets II
- Drag and Drop in wxWidgets
- Device Contexts in wxWidgets
- Custom widgets in wxWidgets
- The Tetris game in wxWidgets
- wxPython tutorial
- Introduction to wxPython
- First Steps
- Menus and toolbars
- Layout management in wxPython
- Events in wxPython
- wxPython dialogs
- Widgets
- Advanced widgets in wxPython
- Drag and drop in wxPython
- Internationalisation
- Application skeletons in wxPython
- The GDI
- Mapping modes
- Creating custom widgets
- Tips and Tricks
- wxPython Gripts
- The Tetris game in wxPython
- C# Winforms Mono tutorial
- Java Gnome tutorial
- Introduction to Java Gnome
- First steps in Java Gnome
- Layout management in Java Gnome
- Layout management II in Java Gnome
- Menus in Java Gnome
- Toolbars in Java Gnome
- Events in Java Gnome
- Widgets in Java Gnome
- Widgets II in Java Gnome
- Advanced widgets in Java Gnome
- Dialogs in Java Gnome
- Pango in Java Gnome
- Drawing with Cairo in Java Gnome
- Drawing with Cairo II
- Nibbles in Java Gnome
- QtJambi tutorial
- GTK+ tutorial
- Ruby GTK tutorial
- GTK# tutorial
- Visual Basic GTK# tutorial
- PyGTK tutorial
- Introduction to PyGTK
- First steps in PyGTK
- Layout management in PyGTK
- Menus in PyGTK
- Toolbars in PyGTK
- Signals & events in PyGTK
- Widgets in PyGTK
- Widgets II in PyGTK
- Advanced widgets in PyGTK
- Dialogs in PyGTK
- Pango
- Pango II
- Drawing with Cairo in PyGTK
- Drawing with Cairo II
- Snake game in PyGTK
- Custom widget in PyGTK
- PHP GTK tutorial
- C# Qyoto tutorial
- Ruby Qt tutorial
- Visual Basic Qyoto tutorial
- Mono IronPython Winforms tutorial
- Introduction
- First steps in IronPython Mono Winforms
- Layout management
- Menus and toolbars
- Basic Controls in Mono Winforms
- Basic Controls II in Mono Winforms
- Advanced Controls in Mono Winforms
- Dialogs
- Drag & drop in Mono Winforms
- Painting
- Painting II in IronPython Mono Winforms
- Snake in IronPython Mono Winforms
- The Tetris game in IronPython Mono Winforms
- FreeBASIC GTK tutorial
- Jython Swing tutorial
- JRuby Swing tutorial
- Visual Basic Winforms tutorial
- JavaScript GTK tutorial
- Ruby HTTPClient tutorial
- Ruby Faraday tutorial
- Ruby Net::HTTP tutorial
- Java 2D games tutorial
- Java 2D tutorial
- Cairo graphics tutorial
- PyCairo tutorial
- HTML5 canvas tutorial
- Python tutorial
- Python language
- Interactive Python
- Python lexical structure
- Python data types
- Strings in Python
- Python lists
- Python dictionaries
- Python operators
- Keywords in Python
- Functions in Python
- Files in Python
- Object-oriented programming in Python
- Modules
- Packages in Python
- Exceptions in Python
- Iterators and Generators
- Introspection in Python
- Ruby tutorial
- PHP tutorial
- Visual Basic tutorial
- Visual Basic
- Visual Basic lexical structure
- Basics
- Visual Basic data types
- Strings in Visual Basic
- Operators
- Flow control
- Visual Basic arrays
- Procedures & functions in Visual Basic
- Organizing code in Visual Basic
- Object-oriented programming
- Object-oriented programming II in Visual Basic
- Collections in Visual Basic
- Input & output
- Tcl tutorial
- C# tutorial
- Java tutorial
- AWK tutorial
- Jetty tutorial
- Tomcat Derby tutorial
- Jtwig tutorial
- Android tutorial
- Introduction to Android development
- First Android application
- Android Button widgets
- Android Intents
- Layout management in Android
- Android Spinner widget
- SeekBar widget
- Android ProgressBar widget
- Android ListView widget
- Android Pickers
- Android menus
- Dialogs
- Drawing in Android
- Java EE 5 tutorials
- Introduction
- Installing Java
- Installing NetBeans 6
- Java Application Servers
- Resin CGIServlet
- JavaServer Pages, (JSPs)
- Implicit objects in JSPs
- Shopping cart
- JSP & MySQL Database
- Java Servlets
- Sending email in a Servlet
- Creating a captcha in a Servlet
- DataSource & DriverManager
- Java Beans
- Custom JSP tags
- Object relational mapping with iBATIS
- Jsoup tutorial
- MySQL tutorial
- MySQL quick tutorial
- MySQL storage engines
- MySQL data types
- Creating, altering and dropping tables in MySQL
- MySQL expressions
- Inserting, updating, and deleting data in MySQL
- The SELECT statement in MySQL
- MySQL subqueries
- MySQL constraints
- Exporting and importing data in MySQL
- Joining tables in MySQL
- MySQL functions
- Views in MySQL
- Transactions in MySQL
- MySQL stored routines
- MySQL Python tutorial
- MySQL Perl tutorial
- MySQL C API programming tutorial
- MySQL Visual Basic tutorial
- MySQL PHP tutorial
- MySQL Java tutorial
- MySQL Ruby tutorial
- MySQL C# tutorial
- SQLite tutorial
- SQLite C tutorial
- SQLite PHP tutorial
- SQLite Python tutorial
- SQLite Perl tutorial
- SQLite Ruby tutorial
- SQLite C# tutorial
- SQLite Visual Basic tutorial
- PostgreSQL C tutorial
- PostgreSQL Python tutorial
- PostgreSQL Ruby tutorial
- PostgreSQL PHP tutorial
- PostgreSQL Java tutorial
- Apache Derby tutorial
- SQLAlchemy tutorial
- MongoDB PHP tutorial
- MongoDB Java tutorial
- MongoDB JavaScript tutorial
- MongoDB Ruby tutorial
- Spring JdbcTemplate tutorial
- JDBI tutorial
Introduction to Stripes
This is an introductory Stripes tutorial. We create two simple web applications with the Stripes web framework. We use NetBeans to build the applications.
Stripes is an open source lightweight Java web application framework. The goal of Stripes is to make Servlet/JSP based web development in Java easy, intuitive, and straightforward. Stripes is an action based MVC (Model View Controller) framework. It runs in a JEE web container, uses minimum configuration files, and has a flexible and simple parameter binding.
Stripes' ActionBean is an object that receives the data submitted in requests and processes the user's input. It both defines the properties of the form and the processing logic for the form. Stripes auto-discovers ActionBeans at deployment time by scanning the web application's classpath. The ActionResolver.Packages
init-param
of the Stripes Filter (in web.xml
) sets one or more package roots.
Resolution is an object created as a response to the processed request. A Resolution can forward to a JSP page, stream data, or return an error message. Resolutions are returned by handler methods of ActionBeans.
From the Stripes' Github page , we download the latest Stripes release. In the lib subdirectory, we have the three JAR files that we need to include in our projects: commons-logging-1.1.3.jar
, cos-05Nov2002.jar
, and stripes-1.6.0.jar
. In addition, there is also the StripesResources.properties
file which contains various messages.
Simple Stripes application
The first application displays the current date. We create a new web application in NetBeans. We choose Tomcat as our JSP/servlet cointainer.

The project has three files: the HelloActionBean.java
contains code which responds to our request, the showDate.jsp
is the view sent as a response back to the user, and the web.xml
file contains configuration to set up Stripes. In this application, we do not use StripesResources.properties
.

These are the libraries that we need to build the Stripes application.
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <filter> <display-name>Stripes Filter</display-name> <filter-name>StripesFilter</filter-name> <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> <init-param> <param-name>ActionResolver.Packages</param-name> <param-value>com.zetcode.action</param-value> </init-param> </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> <welcome-file-list> <welcome-file>Hello.action</welcome-file> </welcome-file-list> </web-app>
In the standard web.xml
deployment descriptor, we configure Stripes. We specify where Stripes should look for ActionBeans: in our case it is the com.zetcode.action
package. The welcome file is the file that is displayed when we request the home page; the Hello.action
tells that the HelloActionBean
should be executed.
HelloActionBean.java
package com.zetcode.action; import java.util.Date; import net.sourceforge.stripes.action.ActionBean; import net.sourceforge.stripes.action.ActionBeanContext; import net.sourceforge.stripes.action.DefaultHandler; import net.sourceforge.stripes.action.ForwardResolution; import net.sourceforge.stripes.action.Resolution; public class HelloActionBean implements ActionBean { private static final String VIEW = "/WEB-INF/jsp/showDate.jsp"; private ActionBeanContext context; private Date date; public Date getDate() { return date; } public void setDate(Date date) { this.date = date; } @Override public void setContext(ActionBeanContext context) { this.context = context; } @Override public ActionBeanContext getContext() { return context; } @DefaultHandler public Resolution hello() { this.date = new Date(); return new ForwardResolution(VIEW); } }
The HelloActionBean
processes the requests and responds with a forward resolution to a JSP page.
private static final String VIEW = "/WEB-INF/jsp/showDate.jsp";
The view is the showDate.jsp
file.
private ActionBeanContext context;
ActionBeanContext
encapsulates information about the current request. It provides access to the underlying Servlet API should we need to use it for any reason.
@DefaultHandler public Resolution hello() { this.date = new Date(); return new ForwardResolution(VIEW); }
The @DefaultHandler
annotation sets the default handler for this action bean. It fills the date
property with current date and returns a new ForwardResolution
. The resolution forwards to the view.
showDate.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Current date</title> </head> <body> <h3>The date is ${actionBean.date}</h3> </body> </html>
This is the template view for the user. The ${actionBean}
expression refers to the action bean that pointed to this view. We use the expression to refer to the action bean's date
property.
$ curl localhost:8084/SimpleStripes/ <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Current date</title> </head> <body> <h3>The date is Thu Jun 02 14:13:01 CEST 2016</h3> </body> </html>
After we build and deploy the application, we access the home page of the application with the curl
tool. The application responds with an HTML page that contains the current date.
Hello Stripes application
In the second application, we have a simple HTML form. The user specifies his name in a text box. The application responds with a greeting. Validation is used to ensure that the user has entered something into the text field.
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1"> <filter> <display-name>Stripes Filter</display-name> <filter-name>StripesFilter</filter-name> <filter-class>net.sourceforge.stripes.controller.StripesFilter</filter-class> <init-param> <param-name>ActionResolver.Packages</param-name> <param-value>com.zetcode.action</param-value> </init-param> </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> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
In the web.xml
file, we set the index.jsp
file to be the welcome file.
index.jsp
<%@taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%> <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Enter your name</title> </head> <body> <stripes:form beanclass="com.zetcode.action.HelloActionBean"> <stripes:errors/> Enter your name: <stripes:text name="userName"/> <stripes:submit name="save" value="Submit"/> </stripes:form> </body> </html>
The index.jsp
contains a simple HTML form. Stripes has its own tags. The <stripes:errors/>
displays validation errors. If we do not write any text into the field, a validation error is shown. In the <stripes:form>
tag we specify the action bean which should process the request. The <stripes:text/>
creates a text field. The created request parameter is automatically mapped to the userName
property of the HelloActionBean
.

StripesResources.properties
is the default resource bundle for the Stripes framework. It contains values for various messages and labels. A sample file is included in the lib subdirectory of the Stripes download file. We put the file into the source packages, with no package specified. (The file should end up in the WEB-INF/classes
directory.)
StripesResources.properties
... validation.required.valueNotPresent={0} is a required field ...
This error message is shown when we do not enter anything into the text field and click on the Submit button.
HelloActionBean.java
package com.zetcode.action; import net.sourceforge.stripes.action.ActionBean; import net.sourceforge.stripes.action.ActionBeanContext; import net.sourceforge.stripes.action.DefaultHandler; import net.sourceforge.stripes.action.ForwardResolution; import net.sourceforge.stripes.action.Resolution; import net.sourceforge.stripes.validation.Validate; public class HelloActionBean implements ActionBean { private static final String VIEW = "/WEB-INF/jsp/greet.jsp"; private ActionBeanContext context; @Validate(required=true) private String userName; public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } @Override public void setContext(ActionBeanContext context) { this.context = context; } @Override public ActionBeanContext getContext() { return context; } @DefaultHandler public Resolution greet() { return new ForwardResolution(VIEW); } }
HelloActionBean
is executed when we click on the Submit button. The request parameter is automatically bound to its userName
property. The default handler forwards to the greet.jsp
view.
@Validate(required=true) private String userName;
The @Validate
annotation is used to enforce validation for the user name field of the form. An error message is displayed if no value is entered.

The second view in our application is greet.jsp
.
greet.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="stripes" uri="http://stripes.sourceforge.net/stripes.tld"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Greeting</title> </head> <body> <h3>Hello ${actionBean.userName}</h3> </body> </html>
The greet.jsp
shows a greeting message for the user. With the ${actionBean.userName}
expression we get the name of the user.

The application responds with a simple message.
In this tutorial, we have created two simple web applications with the Stripes web framework. You might be also interested in ZetCode's Java tutorial , Validation filter tutorial , Introduction to Play framework , Introduction to Spark Java , Stripes, MyBatis & Derby tutorial , or EJB tutorial .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论