java servlet服务端分发forward 客户端重定向redirect spring设置首页
- 2016-11-22 22:01:00
- admin
- 原创 1938
一、servlet服务端分发forward
<jsp:forward page="test_get.do?name=feinen"></jsp:forward>
二、servlet客户端重新向(返回302状态码)
方法1:
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<c:redirect url="test_get.do?name=feinen"/>
方法2:
<%
response.sendRedirect("test_get.do?name=feinen");
%>
返回:
HTTP/1.1 302 Found
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=C37EF00D5845F2311166BFD8B1243EA4; Path=/springmvc/; HttpOnly
Location: http://localhost:8080/springmvc/static/index.html
Content-Type: text/html
Content-Length: 0
Date: Wed, 23 Nov 2016 14:10:31 GMT
三、spring设置首页
步骤1:
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
步骤2:index.jsp内容
<%
response.sendRedirect("static/index.html");
%>
踩过的坑:
不能直接在welcome-file里面写static/index.html,因为没办法找到index.html依赖的资源。