1、web.xml文件 
<?xml version="1.0" encoding="UTF-8"?> 
<web-app id="WebApp_ID" version="2.4" 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"> 
<display-name> 
struts2</display-name> 
<filter> 
<filter-name>struts2</filter-name> 
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> 
</filter> 
<filter-mapping> 
<filter-name>struts2</filter-name> 
<url-pattern>/*</url-pattern> 
</filter-mapping> 
<welcome-file-list> 
<welcome-file>index.html</welcome-file> 
<welcome-file>index.htm</welcome-file> 
<welcome-file>index.jsp</welcome-file> 
<welcome-file>default.html</welcome-file> 
<welcome-file>default.htm</welcome-file> 
<welcome-file>default.jsp</welcome-file> 
</welcome-file-list> 
</web-app> 
其中,绿底色的部分是通用的部分。 
2、struts.xml文件 
这个文件的配置是最为重要的,也是比较容易出问题的地方,初学者对其中很多的参数不太明白,导致调试时候经常出错。下面先给出一个配置的代码: 
<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
"
http://struts.apache.org/dtds/struts-2.0.dtd"> 
<struts> 
<include file="struts-default.xml"/> 
<package name="package1" extends="struts-default"> 
<action name="Hello" class="tutorial.HelloWorld"> 
<result>HelloWorld.jsp</result> 
</action> 
<action name="HelloWorld" class="package1.HelloWorld"> 
<result>HelloWorld.jsp</result> 
</action> 
</package> 
</struts> 
1)对于<include file="struts-default.xml"/>这行代码,可以要也可以不要。 
2)package的name是可以虚构的,并不一定要在classes目录下要有一个与这个name名对应的包名;像上面的配置文件中的name="package1"可以随便改成name="aaa"等是不影响结果的,只不过这个package名可以使得多个action聚合在一起,对大型的模块设计的时候是很有帮助的。 
3)<action name="HelloWorld" class="package1.HelloWorld">中的HelloWorld这个name并不一定要与package1包中的类名相同,比如<action name="Hello" class="tutorial.HelloWorld">这样两个名字完全不一样是可以的,但是"Hello"这个name必须与输入的jsp页面里面的action内容是一致的,如<s:form action="Hello"> 
4)从上面的配置文件可以看出,在classes目录下面有两个包,一个是tutorial,一个是package1。 
3、struts.properties文件 
这个文件最简单,它与struts.xml文件一样,都是位于classes目录下面。其内容为: 
struts.devMode = true 
struts.enable.DynamicMethodInvocation = false的 
4、建议初学者先看看为Struts 2.0做好准备这篇文章,这里每个步骤讲的非常的详细,但是有些细节作者没有写出来,让很多初学者调试的时候出很多错误,比如The requested resource (/项目名/HelloWorld) is not available.,java.lang.NullPointerException等等。 
1)关于工具web tools platform,这是一个eclipse集成了很多web开发下所需工具的一个比较好的平台,它在eclipse的网站下面
http://www.eclipse.org/webtools/有下载。打开这个页面的右边download栏目下面有wtp的下载,点击这个去下载,如果不行,就再仔细找找了。 
2)如果出现The requested resource (/项目名/HelloWorld) is not available.的话,就仔细找找看是不是输入的时候把配置文件等等地方写错了,对于初学者最容易把其中的字母搞错,比如struts是不写成了其它的形式,反正出现这个错误就是说访问的资源不存在,那就肯定要么是配置文件出错了,要么是你的类文件没有放在classes目录下面,无外这两种情况。错了不要紧,没有错误,哪会有进步呢。 
3)如果你真的发现什么错误都没有,但就是尽管调试了半天还是调试不成功,那就考虑你的JDK版本是不是和你下载的wtp搭配了,建议把原来低版本的JDK卸载,装上新去下载的JDK,写这篇博客时,最新版本是jdk-1_5_0_10。如果还不行,你就把tomcat或者其它的web服务器换版本,总之要不怕错误和失败,要勤于不断的调试。 
	
posted on 2007-08-13 01:41 
jadmin 阅读(58) 
评论(0)  编辑  收藏