spring MVC访问WEB-INF下资源问题

1、web项目的WEB-INF

这个目录下的页面是不能直接访问的,为了安全考虑,我们把jsp页面都放到这里,所以就造成了一个问题,访问页面前都要经过控制器来跳转。

2、解决办法

jsp页面,要引入bootstrap,不引入也没事,就是没有样式而已。

<%--
  Created by IntelliJ IDEA.
  User: qqg
  Date: 2017/8/14
  Time: 23:05
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=utf-8"
         pageEncoding="utf-8"%>
<%
    String path = request.getContextPath();
    HttpSession s = request.getSession();
    String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
    <script type="text/javascript" src="/js/jquery.min.js"></script>
    <link href="/css/bootstrap.min.css" rel="stylesheet">
    <script src="/js/bootstrap.js"></script>
    <title>index页面</title>
</head>
<body>
    <div class="container">
        <div class="row">
            <div class="col-md-6 col-md-offset-3" style="text-align: center;">
                <h1>Exam 0815电影租赁系统</h1>
            </div>
        </div>
        <div class="row" style="margin-top: 100px;">
            <div class="col-md-6 col-md-offset-3" style="text-align: center;">
                <div>
                        <button class="btn-success" id="btn_login" style="width: 100%;">登录</button>
                </div>
            </div>
        </div>
    </div>
</body>
<script>
    $(function () {
        $("#btn_login").click(function () {
        //点击跳转到后台
            location.href = "${pageContext.request.contextPath}/index";
        });
    });
</script>
</html>

后台处理

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
/**
 * Created by qqg on 2017/8/15.
 */
@Controller
public class CustomerController {
    @Autowired
    CustomerService customerService;
    @Autowired
    private HttpServletRequest request;
    @RequestMapping(value="/index",method= RequestMethod.GET)
    public String publishArticle(){
        System.out.println("index");
        return "login";
    }
    //signOut
    @RequestMapping(value="/signOut",method= RequestMethod.GET)
    public String signOut(){
        //清空session,回到首页
        getSession().invalidate();
        return "login";
    }

点击主页会跳转到login页面。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值