Create Struts 2 Web Application With Artifacts In WEB-INF lib and Use Ant To Build The Application Edit Page Browse Space Add Page Add News You can download this complete example, Basic_Struts2_Ant, from Google Code - https://www.sodocs.net/doc/4b824805.html,/p/struts2-examples/downloads/list. Click on the link for Basic_Struts2_Ant.zip and save the file to your computer. Unzip the file and you should have a folder named Basic_Struts2_Ant. In that folder is a README.txt file with instruction on how to build and run the application. Icon This tutorial assumes you already know how to create a Java web application, use Ant to build the web application archive (war) file, and deploy the war file to a Servlet container such as Tomcat or Jetty. To create a Struts 2 web application with the Struts 2 artifacts added to the the application's class path manually you will need to download the Struts 2 distribution from the Apache Struts website. On the Struts 2 download page, click on the link for the current General Availability release. In that release's section you'll find several links. To get started with a basic Struts 2 web application you need to only download the Essential Dependencies Only zip file, which is approximately 12mb. After downloading this zip file, unzip it. You should have a folder named the same as the current general availability release and in that folder will be a lib folder. The lib folder contains the Struts 2 jar files (e.g. struts2-core-X.X.X.X.jar, where X.X.X.X is the version) and other jar files Struts 2 requires (e.g. xwork-core.X.X.X.jar). As we create our basic Struts 2 web application we will copy from the Struts 2 distribution lib folder just the jar files our application requires. As we add features to our application in future tutorials we will copy other jar files. Step 1 - Create A Basic Java Web Application In your Java IDE create a web application project named Basic_Struts2_Ant. To follow along with this tutorial your web application should have the following folder structure: Remember Struts 2 requires Servlet API 2.4 or higher, JSP 2.0 or higher, and Java 5 or higher. The example project, Basic_Struts2_Ant, which you can download from Google
一、第一个异常处理 严重: Servlet.service() for servlet jsp threw exception The 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] at org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60) at org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44) at https://www.sodocs.net/doc/4b824805.html,ponentTagSupport.doStartTag(ComponentTagSupport.java:48) at https://www.sodocs.net/doc/4b824805.html,_005fstruts2_005flz.YpxxbQuery_jsp._jspx_meth_s_005fdebug_005f0(Ypxxb Query_jsp.java:108) at https://www.sodocs.net/doc/4b824805.html,_005fstruts2_005flz.YpxxbQuery_jsp._jspService(YpxxbQuery_jsp.java:83) 解决的办法:(4种解决方案) 1. web.xml 中添加一个filter struts2*.jspstruts2/action/* 2. struts2/* 注意这里一定要是/* 3. 这通常是由于不经由Filter访问包含struts标签的jsp页面导致的。那么,只要通过配置,使得对jsp页面的访问请求由Filter过滤转发即可。 方法1:在strut.xml中配置一个通用Action,通过这个Action转发到jsp页面。这个时候,原先访问jsp的请求路径就要换成相应的Action路径了。写法如下。 /{1}.jsp 方法2:在web.xml中配置Filter的url-parttern。写法如下。其中struts2-dispatcher 是已定义的Filter。