Java Reference
In-Depth Information
Mind the Context Path!
When you deploy web applications to a servlet container, the
context path distinguishes one application from another. With
Jetty and Tomcat, for example, an application deployed by
placing the myapp.war file in the /webapps directory has a con-
text path of /myapp . You can then access the root of the web
application with http://localhost:8080/myapp .
Avoid using the same name for the context path of your
web application and for the first part of the package
name that contains your action beans—for example, a
context path named /myapp and an action bean named
myapp.mymodule.ui.MyActionBean . This will cause problems with
the URL binding mechanism.
If you must use the same name for the context path and
the first package name, place your action beans in a pack-
age that includes one of the names that are truncated by
the URL binding strategy ( action , stripes , web , or www ), such as
myapp.mymodule.ui.stripes.MyActionBean .
• If you decide to move or rename the action bean, modern IDEs will
catch the beanclass= references in the refactoring process.
Nevertheless, it's useful to understand how URL binding works. For
example, you might need to create links to action beans within non-
Stripes tags or from an application that uses a different framework.
The Preaction Pattern
A good practice in a Stripes application is to use what is known as
the preaction pattern. This consists of always having requests go to
action beans rather than directly to JSPs. We did this in the example—
both links target HelloActionBean using the beanclass= attribute of the
<s:link> tag. There are no direct links to hello.jsp . In fact, we made sure
of that by placing the JSP file in the /WEB-INF/jsp directory. In Java web
applications, files anywhere under /WEB-INF cannot be accessed by the
browser.
Using the preaction pattern has the following advantages:
• Ensures that the current action bean will be available in the JSP
using ${actionBean}
 
 
 
Search WWH ::




Custom Search