开发者

First example in struts 2 tutorial

I want to start using Struts 2 framework, I download Struts 2.2.3 , and follow this tutorial to make first example, but when I run the index.jsp which has

<%@ taglib prefix="s"  uri="/struts-tags" %>
 ....
<p><a href="<s:url action='hello'/>">Hello World</a></p>
..

This exception occurs:

org.apache.jasper.JasperException: 开发者_如何学GoThe Struts dispatcher cannot be found.  This is usually       caused by using Struts tags without the associated filter. Struts tags are only usable when the  request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]

I didn't specify any filters in web.xml because web.xml file wass not created when I create the web application ?! There's only sun-web.xml file that exists.


From the tutorial which you linked yourself.

Step 5 - Add Struts 2 Servlet Filter

To enable the Struts 2 framework to work with your web application you need to add a Servlet filter class and filter mapping to web.xml. Below is the filter and filter-mapping nodes you should add to web.xml.

web.xml Servlet Filter

<filter>
  <filter-name>struts2</filter-name>
  <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>

<filter-mapping>
  <filter-name>struts2</filter-name>
  <url-pattern>/*</url-pattern>
</filter-mapping>

For more information about configuring the deployment descriptor for Struts 2 see web.xml. Note the url-pattern node value is /* meaning the Struts 2 filter will be applied to all URLs for this web application.

Did you read it? Create the web.xml (the IDE should usually already have done it) and declare the filter in there as per the instructions in the tutorial.


If you start with Struts2 take a look at the Maven Archtypes. How it works is described here.

4 Easy Steps to create a Java based Web Application with Struts2 and jQuery

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜