Struts2 DefaultAction (默认Action) 以及如何屏蔽404

defaultAction是什么意思呢?

默认的Action!

<default-action-ref name="index"></default-action-ref>
默认的action的引用;当别人访问这个action的时候,如果找不到对应的action

默认就用这个action了,

如果没有默认action的引用,那么我们在url中输入一个地址时候,action不能在struts.xml

文件中找到,那么这时就会报错,但是如果有了默认的action引用,就不会出现这种情况了

--------------------------------------Hongten-----------------------------------

struts.xml

代码:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
    <constant name="struts.devMode" value="true" />
    
    <package name="default" namespace="/" extends="struts-default">
     <default-action-ref name="index"></default-action-ref>
     <action name="index">
      <result>/default.jsp</result>
     </action>
    </package>
</struts>

--------------------------------------Hongten-----------------------------------

default.jsp

代码:

<?xml version="1.0" encoding="GB18030" ?>
<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
    <%@taglib uri="/struts-tags" prefix="s" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030" />
<title>DefaultAction</title>
</head>
<body>
Default Action!
</body>

</html>



-----------------------------------------  屏蔽404 ----------------------------------------------------------

配置web.xml 
<error-page> 
<error-code>404</error-code> 
<location>/WEB-INF/errorpage/404.jsp</location> 
</error-page> 

不要配置struts.xml 
那只能定义某个namespace下的页面未找到的错误。 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值