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";
}