首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

c:redirect的用法解决办法

2012-01-28 
c:redirect的用法web.xml:welcome-file-listwelcome-file/index.jsp/welcome-filewelcome-file/in

c:redirect的用法
web.xml:
  <welcome-file-list>
<welcome-file>/index.jsp</welcome-file>
<welcome-file>/index.html</welcome-file>
</welcome-file-list>

webRoot下的index.jsp:
  <%@page contentType="text/html; charset=UTF-8"%>
  <%@ include file="/commons/taglibs.jsp"%>
  <c:redirect url="/login/"/>

webRoot的目录结构:
  |----webRoot
  |-----login
  |---------login.jsp
  |---------index.jsp
  |-----index.jsp


为什么跳转到的页面是login目录下的index.jsp而不是login.jsp,c:redirect标签用的不是很熟,望知情兄点拨一二,不胜感激,拜谢!

[解决办法]
第一个 代码运行的方式是由上而下的 那么在web.xml中代码首先运行到
<welcome-file>/index.jsp</welcome-file>
如果找到,就会显示index.jsp,如果没找到index.jsp就会继续运行到
<welcome-file>/index.html</welcome-file>即显示index.html,至于两个都没找到会怎样,呵呵,你自己去试试吧

第二个 当用户没有指定访问某个目录上的哪个页面时,就会默认访问index.jsp或者index.html

第三个 c:redirect是把用户请求重定向的标签,你那<c:redirect url="/login/"/>是把目录重定向到login目录里面去了,又由于上面第二个原因,所以就导航到login/index.jsp里面去了
你可以试试改成<c:redirect url="/login/login.jsp"/>看是否显示login里的login.jsp就知道了

呵呵,不知道我说的对不对

热点排行
Bad Request.