风人园

弱水三千,只取一瓢,便能解渴;佛法无边,奉行一法,便能得益。
随笔 - 99, 文章 - 181, 评论 - 56, 引用 - 0
数据加载中……

Struts 2.0 起步

参考 http://www.blogjava.net/max/category/16130.html

1、添加struts2的jar包,struts2-core-2.x.x.jar, struts2-api-2.x.x.jar (struts2-all-2.x.x.jar即可,其他的struts2的插件包已经包含在里面)。
   如添加其他的插件包,可能会出现文件重复,具体可以看异常信息。
   或者不要加all包,而使用插件包,可以减小包的大小。
2、修改web.xml

 1 <? xml version="1.0" encoding="UTF-8" ?>
 2 < web-app  version ="2.4"  
 3  xmlns ="http://java.sun.com/xml/ns/j2ee"  
 4  xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance"  
 5  xsi:schemaLocation ="http://java.sun.com/xml/ns/j2ee 
 6  http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
 7   < display-name > Struts2 Hello World! </ display-name >   
 8
 9     < filter >
10          < filter-name > Struts2 </ filter-name >
11          < filter-class >
12             org.apache.struts2.dispatcher.FilterDispatcher
13          </ filter-class >
14      </ filter >
15      < filter-mapping >   
16          < filter-name > Struts2 </ filter-name >   
17          < url-pattern > /* </ url-pattern >   
18      </ filter-mapping >   
19 </ web-app >
20


3、在classpath下添加struts.properties文件,内容如下
struts.devMode = true
struts.enable.DynamicMethodInvocation = false

4、在classpath下添加struts.xml,这个是对应struts1.x里面的struts-config.xml

 1 <! DOCTYPE struts PUBLIC
 2         "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
 3         "http://struts.apache.org/dtds/struts-2.0.dtd" >
 4 < struts >
 5      < package  name ="example"  extends ="struts-default" >
 6          < action  name ="hello"  class ="com.ivo.struts2.HelloWorld"  method ="aliasAction" >
 7              < result > /hello.jsp </ result >
 8          </ action >
 9          < action  name ="Login"  class ="com.ivo.struts2.Login" >
10        < result > /hello.jsp </ result >
11    </ action >
12    < action  name ="LoginX"  class ="com.ivo.struts2.LoginX" >
13        < result > /hello.jsp </ result >
14    </ action >
15      </ package >
16 </ struts >


注意,struts2的两个相关文件需要放在classpath下

posted on 2006-12-29 10:09 风人园 阅读(507) 评论(0)  编辑  收藏 所属分类: Struts2


只有注册用户登录后才能发表评论。


网站导航: