受保护目录WEB-INF下jsp之间的互相访问

 

我们说WEB-INF目录下有 *.xml classes lib 等目录和文件,它们一般都是不让直接访问的。

说明这个目录是安全的,我们回想为什么不把jsp、html等页面文件放进去呢?

这样会不会安全一些呢?大家猜的不错,这样是安全了(使用过滤器也可以实现该功能),

有一个路径问题需要解决,使用页面入口问题,如果页面文件放在WEB-INF目录下,用户访问

WEB-INF目录下页面文件会报找不到页面,用户该怎么才能访问到网站页面呢?

如果liandong.jsp放在WEB-INF/jsp目录下,Web Context-root为:liandong那么

1.我们可以在WebRoot下新建index.jsp,其中的代码为:

<jsp:forward page="WEB-INF/jsp/liandong.jsp"></jsp:forward>

2.我们可以在struts-config.xml配置代码:

<action path="/test" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="liandong" path="/WEB-INF/jsp/liandong.jsp"></forward>   
   </action>

action 中代码为:

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
// TODO Auto-generated method stub
// method 2
return mapping.findForward("liandong");
}

index.jsp代码为:<a href="test.do">link–>liandong</a>

3.我们可以在action 中写代码:

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
// TODO Auto-generated method stub
System.out.println("bbb");
RequestDispatcher rd = request.getRequestDispatcher("WEB-INF/jsp/liandong.jsp");

rd.forward(request,response);

return null;
}

index.jsp代码为:<a href="test.do">link–>liandong</a>

struts-config.xml配置代码:

<action path="/test" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="liandong" path="/WEB-INF/jsp/liandong.jsp"></forward>   
   </action>

4.action 中

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
   HttpServletRequest request, HttpServletResponse response)
   throws Exception {
// TODO Auto-generated method stub
System.out.println("bbb");

return new ActionForward("/WEB-INF/jsp/liandong.jsp");
}

index.jsp代码为:<a href="test.do">link–>liandong</a>

struts-config.xml配置代码:

<action path="/test" scope="request"
    type="org.springframework.web.struts.DelegatingActionProxy">
<forward name="liandong" path="/WEB-INF/jsp/liandong.jsp"></forward>   
   </action>

还有个问题就是,层叠样式文件、js脚本文件、图片文件的路径

1.页面访问图片

background-image: url(‘/liandong/images/bg.bmp’)

2.页面访问层叠样式文件

<link rel="stylesheet" href="/liandong/css/liandong.css" type="text/css"></link>

3.页面访问js脚本文件

<script type="text/javascript" src="/liandong/js/liandong.js"></script>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值