一.页面跳转方式
1.1 JavaScript方式跳转
<%@ 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>
<body>
<!--
页面跳转的方式
1.通过HTML超链接的方式进行跳转
<a href = "路径">资源地址</a>
2.通过js的location对象进行页面跳转
window.location.href = "路径";
-->
<!-- 通过超链接跳转到index.jsp页面 -->
<button onclick = "add();">跳转到index.jsp</button>
<script type="text/javascript">
function add(){
/* 通过js的location对象进行页面跳转 */
location.href = "index.jsp?result=123";
}
</script>
</body>
</html>
<%@ page import="java.util.Scanner" %>
<%@ 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>
<body>
<h2>欢迎来到我的主页</h2>
<%
request.setCharacterEncoding("utf-8");//设置编码
//获取超链接上携带的参数
String username = request.getParameter("username");
out.println("用户名为: "+username);
/* 获取jslocation对象.href中携带的参数 */
String result = request.getParameter("result");
out.println("<br/>result