标签:配置文件 str apache 生成 extend 乱码问题 names location dex
1,MVC框架完成的事情
| ServLet | strtus2 | |
| 默认执行方法 | service | execute |
| 方法参数 | HttpServLetRequest, HttpServletRespones | 无 |
| 返回值 | 无 | String |
| 方法 | 都是public |
<struts> <!--extends必须写,直接或间接继承struts-default name自定义--> <package name="hello" extends="struts-default"> <!--name是请求名称,不要写/;class对应action完全限定名==包名+类名--> <action name="hello" class="包名.类名"> <!--result是结果集,name和对应action中--> <result name="success">/index.jsp</result> </action> </package> </struts>
<include file="文件位置"></include>
<!--name: 包的名称自定义,可以配置多个包;
namespace命名空间:不同模块可以指定不同的空间
extends 值是直接或者间接继承struts-default
-->
<package name="default" namespace="/" extends="struts-default">
</package>
<!-- name:是URL请求名,不需要加后缀(.action) class:是处理URL请求对应的Java类,class要求包名+类名,并且该类是由公共的无参构造方法的 method:配置处理请求类的处理方法,默认是execute;方法必须满足是公共的,返回值类型是String,无参 --> <action name="login" class="cn.cy.action.LoginAction" method=""> </action>
<!--
name:匹配请求处理方法的返回值,默认是success
type:结果处理类型,默认是dispather转发
type有哪些:
<result-type name="chain" class="com.opensymphony.xwork2.ActionChainResult"/>
chain:指action链,链接下一个action,执行actionA以后直接执行actionB直接执行actionC;
地址栏是执行的第一action
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
dispatcher:转发:和ServLet一致,若request中有数据要多视图显示,那么就是用
<result-type name="freemarker" class="org.apache.struts2.views.freemarker.FreemarkerResult"/>
freemarker:模板
<result-type name="httpheader" class="org.apache.struts2.dispatcher.HttpHeaderResult"/>
httpheader:头文件
<result-type name="redirect" class="org.apache.struts2.dispatcher.ServletRedirectResult"/>
redirect:重定向;如果重定向到jsp页面,可以直接重定向,如果重定向到另一个action,需注意是否配置了action的后缀名,如果 要求有后缀名,那么重定向的action一定要加上后缀名.
<result-type name="redirectAction" class="org.apache.struts2.dispatcher.ServletActionRedirectResult"/>
redirectAction:重定向到另一个action,不用加action的后缀名,会将前一个action的后缀名自动加上
<result-type name="stream" class="org.apache.struts2.dispatcher.StreamResult"/>
stream:以流的形式显示----文件下载
<result-type name="velocity" class="org.apache.struts2.dispatcher.VelocityResult"/>
<result-type name="xslt" class="org.apache.struts2.views.xslt.XSLTResult"/>
<result-type name="plainText" class="org.apache.struts2.dispatcher.PlainTextResult" />
<result-type name="postback" class="org.apache.struts2.dispatcher.PostbackResult" />
-->
<result name="success" type="">/success.jsp</result>
只要name是login的,都跳到login.jsp全局结果集<global-results> <result name="login">/login.jsp</result> </global-results>
<!-- 配置默认执行的class --> <default-class-ref class="包名+类名"></default-class-ref> <!-- 配置默认的action,当所请求的action不存在时,那么执行默认的action --> <default-action-ref name="default"></default-action-ref> <action name="default"> <result>error.jsp</result> </action>
<!-- 使用通配符来配置action,可以减少action的配置,*表示匹配所有,占位符用{1}表示第一个*所代表的内容 -->
<action name="*user*" class="包+类" method="{1}">
<result name="ss">ss.jsp</result>
</action>
public class PojoAction {
public String execute(){
~~~
return "success";
}
}
import com.opensymphony.xwork2.Action;
public class InterfaceAction implements Action{
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return null;
}
}
import com.opensymphony.xwork2.ActionSupport;
public class ExtendsAction extends ActionSupport{
}
标签:配置文件 str apache 生成 extend 乱码问题 names location dex
原文地址:http://www.cnblogs.com/cy666/p/7506061.html