一、思维导图![](https://img-blog.csdnimg.cn/d79f556641284ced8f4ab00f57fc1c02.png?x-oss-process=image/watermark,type_d3F5LXplbmhlaQ,shadow_50,text_Q1NETiBAwqPovbvmj4_vvZ7mt6HlhpnCsA==,size_20,color_FFFFFF,t_70,g_se,x_16)
二、页面的跳转方式
1.通过HTML超链接的方式进行跳转
<a href = "路径">资源地址</a>
2.通过js的location对象进行页面跳转
window.location.href = "路径";
通过超链接跳转到index.jsp页面
通过超链接实现跳转时可以携带参数吗? 可以携带参数,并且可以在目的地通过request对象进行获取该参数-->
注意事项: 第一个参数之前 (?) 参数与参数之间使用(&)
<a href = "index.jsp?username=admin&password=123">跳转到主页</a>
<!-- js跳转 -->
<hr/>
<!-- 通过location跳转可以携带参数 后面可以通过request对象进行获取 -->
<button onclick = "add();">跳转到index.jsp</button>
<script type="text/javascript">
function add(){
/* 通过js的location对象进行页面跳转 */
location.href = "index.jsp?result=123";
}
</script>
中转页面:
作用:
1.获取页面提交的数据
2.进行数据库交互
3.判断是否提交到指定的页面去
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!-- 通过request对象获取数据 脚本区域 -->
<%
//设置编码格式(解决不兼容中文的问题)
request.setCharacterEncoding("utf-8");
//获取用户名和密码
String username = request.getParameter("username");
String password = request.getParameter("password");
//out.println("username="+username+" password = "+password);
//模拟:假设有admin用户,再次注册无效 返回注册页面重登陆 如果不是admin直接注册
if("admin".equals(username)){//我目前注册的账号admin在数据库中已存在 不能注册的
//告诉用户 数据库已存在用户名 不能再次注册 跳回register.jsp页面重写进行注册
//超链接 location跳转 out对象可以拼接标签代码(html js)
out.println("<script>");
out.println("alert('该用户已被注册,请重新进行注册');");
out.println("location.href='register.jsp'");
out.println("</script>");
}else{//可以注册
//直接可以跳转到index.jsp
/* 通过location页面跳转 */
//out.println("<script>");
//out.println("location.href='index.jsp'");
//out.println("</script>");
/* 通过Java的方式 转