struts2的运行流程问题

gistop 2018-08-24 11:58:02
web.xml
<welcome-file-list> 
<welcome-file>index.action</welcome-file>
</welcome-file-list>


struts.xml
<package name="mainindex" extends="basePackage" namespace="/"> 
<interceptors>
<interceptor name="trimInterceptor" class="com.edps.common.TrimInterceptor"/>
<interceptor-stack name="rootStack">
<!-- trim拦截器 -->
<interceptor-ref name="trimInterceptor"/>
<interceptor-ref name="baseStack"/>
</interceptor-stack>
</interceptors>
<!-- 配置默认拦截器栈 -->
<default-interceptor-ref name="rootStack"/>
<global-results>
<result name="login" type="redirect">/auth!chkin.action</result>
<result name="error" type="freemarker">/WEB-INF/template/basicdata/error.ftl</result>
<result name="success" type="freemarker">/WEB-INF/template/basicdata/success.ftl</result>
</global-results>
<action name="index">
<result name="success">system/lightblue1_accordion/main_index.jsp</result>
</action>
<action name="auth" class="com.edps.action.AuthAction" method="chkin">
<result name="in">system/login/index.jsp</result>
<result name="success">system/lightblue1_accordion/main.jsp</result>
</action>
</package>


action类
public class AuthAction extends BaseAction {
.....
public String chkin(){
return "in";
}


public String login(){
return SUCCESS;



流程
1 程序启动,地址栏显示http://localhost/edps/index.action,在struts.xml中找到<action name="index">,因默认返回success,进入system/lightblue1_accordion/main_index.jsp

2 main_index.jsp里面有<a href="/edps/auth!chkin.action" target="_top">,点击后在struts.xml中找到<action name="auth" class="com.edps.action.AuthAction" method="chkin">,执行AuthAction 中的chkin方法,返回in,进入
<result name="in">system/login/index.jsp</result>对应的index.jsp页面

目前为止,我能理解

3 问题:index.jsp页面里面有 <form method="post" class="login_form" action="<%=path%>/auth!login.action">,提交后 这个,该对struts.xml里面的哪个action呢?我看运行结果是到<result name="success">system/lightblue1_accordion/main.jsp</result>这里
我不理解的是auth!login.action这个,因方法是login,应该要对应<action name="auth" class="com.edps.action.AuthAction" method="login">这样的,为什么会进入<action name="auth" class="com.edps.action.AuthAction" method="chkin">??还是我的理解有问题?? 或者auth!login.action这样的,是根据什么来找struts.xml里面的对应action的?
...全文
183 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
getdate 2018-08-24
  • 打赏
  • 举报
回复
<action name="auth" class="com.edps.action.AuthAction" method="chkin">
<result name="in">system/login/index.jsp</result>
<result name="success">system/lightblue1_accordion/main.jsp</result>
</action>

你的配置文件上不是配置的这个地址么肯定是进入chkin方法了啊
931828653 2018-08-24
  • 打赏
  • 举报
回复
首先 你的form表单提交 就是就到你的action里边对应,然后 你的action返回success,<result name="success">system/lightblue1_accordion/main.jsp 转到这个Jsp

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧