我们说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>