404错误处理以及以后缀为action结尾的处理

--------------第一种是胡乱敲,后缀不是以action结尾,出现404错误-----------------------------

解决方法:

web.xml中添加:

404.jsp

测试:

官方解释:

------------------第二种是胡乱敲,后缀是以action结尾,这样会被struts拦截--------------------------

由于是以.action结尾,会被struts拦截,可是找不到匹配的action映射,所以报错。

解决办法:

xml:

<package name="test2" extends="struts-default">

        <default-action-ref name="notFound" />
        <action name="notFound" class="cn.qlq.Action.TestAction2"
            method="notFound">
            <result name="notFound">/404.jsp</result>
        </action>
  </package>

需要提醒的是

  不要给上面的package指定namespace。另外,action的 result 一定要声明。除非在global-results中刚好有一个result 与你的“notFound()”这个方法所要跳转的result的名字 是一样的。

上面的配置的意思就是,在package下配置一个 default action,这个当输入的action找不到的时候,就会使用此action来进行处理。

以上面的配置来说,当一个action找不到时候,就会调用cn.qlq.Action.TestAction2的notFound方法来对应,然后跳转到404.jsp。这个方法的实现如下:

Action:

package cn.qlq.Action;

import com.opensymphony.xwork2.ActionSupport;

public class TestAction2 extends ActionSupport {

    public String notFound() {
        return "notFound";
    }
}

测试:

时间: 2024-08-28 03:29:01

404错误处理以及以后缀为action结尾的处理的相关文章

struts2中&lt;jsp:forward&gt;跳转时报404错误的问题

index.jsp页面: <jsp:forward page="show.action"></jsp:forward> 在struts.xml配置如下: <package name="struts2" extends="struts-dafult"> <action name="show" class="action.ShowAction"> <resu

AspNet Mvc 路由解析中添加.html 等后缀 出现404错误的解决办法

使用Mvc 有时候我们希望,浏览地址以.html .htm 等后缀名进行结尾. 于是我们就在RouteConfig 中修改路由配置信息,修改后的代码如下 routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); routes.MapRoute( name: "Default", url: "{controller}/{action}.html", defaults: new { controller =

java web 404错误页面配置

java web 404错误页面配置:注意红框的地方,在工程的web.xml文件里的最开头加入如下的内容便可,但是也有问题,针对以.action后缀名和.jsp后缀名不起作用, 因为后面配置了一些拦截器专门拦截.action和.jsp文件

Yii 2.0 GII 访问404错误

网上大部分都是普通的开启和配置资料 按照网上资料配置 访问localhost/index/php?r=gii 总是提示404错误 解决方法如下: Yii基础版中的 web.php 代码如下 if (YII_ENV_DEV) { // configuration adjustments for 'dev' environment $config['bootstrap'][] = 'debug'; $config['modules']['debug'] = [ 'class' => 'yii\deb

struts2配置出现404错误

囧死   出现404错误,在网上找了一堆资料,原因有好几个,最后对着自己的弄好了 原因1:jar包的原因,可以从http://struts.apache.org下载struts2包(http://archive.apache.org/dist/struts/binaries/这里可以下载历史版本的),这里解压之后知道入九个jar包分别是(commons-fileupload,commons-io,commons-lang,commons-logging,freemarker,javassist,

对于springmvc 很奇妙的报404错误的记录

@RequestMapping("/editItems") public ModelAndView editItems(Integer id) throws Exception { @RequestMapping("/editItemsSubmit") public String editItemsSubmit(Integer id, ItemsCustom itemsCustom)throws Exception { 上述两段代码,其中/editItems.act

thinkphp nginx php-fpm url rewrite 导致 404 错误

thinkphp nginx php-fpm url rewrite 导致 404 错误 之前thinkphp的系统部署在apache上,考虑到在并发性能nginx比apache强悍得多,所以在centos上以 nginx+php-fpm模式重新部署了thinkphp系统,结果发现诸如 1 /index.php/home/user/verify 此类的url nginx会报404错误,但是改成 1 /index.php?s=/home/user/verify 之后却能够访问,这说明前一种url

Springmvc 访问页面出现404错误

配置springmvc时出错: 我在web.xml中添加 <!-- springMvc配置 --> <servlet> <servlet-name>springMvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- springMvc-XML配置文件 --> <in

atitit.404错误的排查流程总结vOa6

1. 场景 1 1.1. 子应用猛个腊擦不能使用  404 兰.. 1 2. 服务器配置问题 2 2.1. 登录服务器管理子应用,查看应用是否启动okk???? 2 2.2. 80端口已经占用,实际访问的在的服务器端口 2 2.3. #----------jsp  head  errorPage="" 2 2.4. 应用冲突::同时部署了根应用and子应用.. 2 2.5. #------resin 服务器配置问题.俩个应用配置到了同样的的文件夹.. 2 2.6. #---------