详解Struts2中配置默认Action的方法

网友投稿 236 2023-02-27


详解Struts2中配置默认Action的方法

一、jsp默认设置

1、当访问的Action不存在时,页面会显示错误信息,可以通过配置默认Action处理用户异常的操作;

2。配置方法:

在struts.xml文件中的下添加如下内容:

其中index为默认Action的name属性值;

3、配置默认Action后,相应的namespace下不存在要访问的Action时,自动跳转到默认Action处理。

4、实例

web.xml:

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee ;

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

hello.jsp

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

xmlns="http://java.sun.com/xml/ns/javaee"

xmlns:xsi="http://w3.org/2001/XMLSchema-instance"

xsi:schemaLocation="http://java.sun.com/xml/ns/javaee ;

http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

hello.jsp

struts2

org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

struts2

/*

struts.xml:

"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"

"http://struts.apache.org/dtds/struts-2.0.dtd">

/index.jsp

index.jsp:

<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

Welcome to Magci's BLOG!

magci/magc

mgc/magc/magci/123456

二、action默认设置转发

page_toIndex

/WEB-INF/jsps/index.jsp</result>

/WEB-INF/jsps/admin/admin_login.jsp

action


版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:自动化接口测试工具
下一篇:客服接口开发(服务端接口开发)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~