1.跳转功能的实现

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'Jsp5.jsp' starting page</title>


</head>

<body>
<%
pageContext.forward("/index.jsp");
%>
</body>
</html>


2.跳转的时候带参数:

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'Jsp6.jsp' starting page</title>
</head>

<body>

<!--
//测试时把下面的代码删除
<jsp:forward page="/index.jsp"></jsp:forward>

<jsp:include page="/public/head.jsp"></jsp:include> //与PageContext.include()一样是动态包含

-->

<jsp:forward page="/ServletDemo1">
<jsp:param name="data" value="XXX"></jsp:param>
</jsp:forward>

</body>
</html>



ServletDemo1:


import java.io.IOException;
import java.io.PrintWriter;


import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;




public class ServletDemo1 extends HttpServlet {


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();

String data=request.getParameter("data");
out.write("JSP传过来的数据是:");
out.write(data);
}


public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request,response);
}


}


最后在Servlet上拿到jsp文件跳转时传过来的参数。