为何web.xml中的welcome-file-list不能是Action地址
来源:互联网 发布:龙门式数控切割机 编程 编辑:程序博客网 时间:2024/06/05 20:18
问题描述:
有位网友在使用JDiy框架开发项目时,在web.xml中做了如下配置:
1
2
3
4
5
<!-- ..部分代码略.. -->
<
welcome-file-list
>
<
welcome-file
>index.jd</
welcome-file
>
</
welcome-file-list
>
<!-- ..部分代码略.. -->
原本想在访问默认页的时候,直接交由action处理,而运行的时候,却出现404文件未找到的错误。
原因分析:
这是由于web.xml中的welcome-file-list配置段仅对servlet和普通jsp页面有效,而JDiy框架采用的是JDiyLoadFilter来加载的,它是一个Filter而不是Servlet,这也就意味着我们不能将action地址设为默认页。
解决方法:
方法1(采用网页重定向)
首先我们在web.xml中随便定义一个jsp页面作为默认页,代码片段:
1
2
3
4
5
<!-- ..部分代码略.. -->
<
welcome-file-list
>
<
welcome-file
>welcome.jsp</
welcome-file
>
</
welcome-file-list
>
<!-- ..部分代码略.. -->
然后我们再去welcome.jsp中做重定向,代码如下:
1
2
3
4
5
6
<
html
>
<
head
>
<
meta
http-equiv
=
"refresh"
content
=
"0;url=index.jd"
>
</
head
>
<
body
></
body
>
</
html
>
这种方法有一些弊端,如,由于它是客户端重定向(实际上会产生两次请求);浏览器地址栏中的地址也变成了跳转后的地址,不利于用户体验,同时也不利于SEO搜索引擎优化等。
方法2(采用forward action)
这是JDiy官网推荐的方法,那就是直接将请求转发至Action。
首先如同方法1一样,在web.xml中随便定义一个jsp页面作为默认页,如:
1
2
3
4
5
<!-- ..部分代码略.. -->
<
welcome-file-list
>
<
welcome-file
>welcome.jsp</
welcome-file
>
</
welcome-file-list
>
<!-- ..部分代码略.. -->
然后不同的是,welcome.jsp代码变成如下这样:
1
2
3
<%@ page
import
=
"net.jdiy.core.JDiyAction"
%>
<%@ page contentType=
"text/html;charset=UTF-8"
language=
"java"
%>
<% JDiyAction.forwardAction(
"index.jd"
);
return
; %>
这儿我们使用到了JDiyAction类的forwardAction静态方法,直接将请求转发到action,这种方法不会产生多余的请求,浏览器中显示的地址也不会发生改变,是最完美的解决方案~~
0 0
- 为何web.xml中的welcome-file-list不能是Action地址
- Struts2 welcome-file-list 设置的路径不能是Action地址
- struts2 welcome-file-list 设置的路径不能是Action地址
- web.xml中的welcome-file-list不起作用
- web.xml中的welcome-file-list
- 在web.xml中的welcome-file指定动态地址
- 关于web.xml中的welcome-file-list(欢迎页)
- 关于web.xml中的welcome-file-list(欢迎页)
- 关于web.xml中的welcome-file-list(欢迎页)
- web.xml中的welcome-file-list(欢迎页)
- 关于web.xml中<welcome-file-list>
- 关于web.xml中<welcome-file-list>
- web.xml中<welcome-file-list>配置
- <welcome-file-list>action配置
- 关于web.xml中的<welcome-file-list>中的默认首页文件
- 关于web.xml中的<welcome-file-list>中的默认首页文件
- web.xml 中 welcome-file 为action的解决
- web.xml之welcome-file-list、error-page
- 14.5.3 Grouping DML Operations with Transactions 分组DML 事务操作
- JavaWeb-简单查询商品例子
- 计算机视觉进展二十年 (1995~2015)
- go的学习资料点评
- Android 欢迎引导页的魅力
- 为何web.xml中的welcome-file-list不能是Action地址
- :new与:old的用法
- 汇编语言中的常数
- Swift iOS 9通讯录访问
- tomcat开启远程调试
- $_SERVER['REQUEST_URI']获取不到值采用的函数
- CI构造函数
- 常见的http返回码
- 神经网络学习 之 M-P模型