JSP中的response.sendRedirect

时间:2015-10-20 04:29:42

标签: java jsp

这是我目前的JSP代码:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"     "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>


<jsp:useBean id="user" class= "uts.wsd.User" scope="session" ></jsp:useBean>


<% 
String name = request.getParameter("name");
String email = request.getParameter("email");
String password = request.getParameter("password");
String gender = request.getParameter("gender");
String color = request.getParameter("favcol");

user.setName(name);
user.setEmail(email);
user.setPassword(password);
user.setGender(gender);
user.setFavouriteColour(color);
%>
<body style="background: <%= color %>;">

<% if (request.getParameter("tos") == null ) {%>
<p>
Sorry, you must agree to the Terms of Service.</p>
<p>Click <a href="register.jsp" > here </a> to go back.
</p>

<%}  else { %>
    <jsp:forward page="index.jsp" />
<% } %>
</html>

这里我使用jsp:forward page="index.jsp"重定向到index.jsp页面。那么,如果我想使用response.sendRedirect("index.jsp")?我该怎么办?

我试过了:

<% if (request.getParameter("tos") == null ) {%>
<p>
Sorry, you must agree to the Terms of Service.</p>
<p>Click <a href="register.jsp" > here </a> to go back.
</p>

<%}  else { %>
    <response.sendRedirect("index.jsp")>
<% } %>
</html>

但它失败了。请帮忙!谢谢!!

1 个答案:

答案 0 :(得分:1)

val filteredHouses = houses.filter(h => houseKeys.map(hk => h.houseName === hk.houseName && h.houseType === hk.houseType) .reduceOption(_ || _).getOrElse(false: Rep[Boolean]) ) 是Java代码而不是标记,因此在键入之前关闭scriptlet标记,并且不应在response.sendRedirect()之前关闭并关闭< ...它只是Java代码:

>