<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>JSP的九大内置对象</title>
<%-- 五个常见的内置对象
特点:不需要新建实例,是JSP当中的关键字(保留字)
request
response
session
application
out
四个其他内置对象
page
pageContext
exception
config
--%>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
This is my JSP page. <br>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<%-- <base href="<%=basePath%>">
默认的提交标签,basePath是需要将这一行代码注释掉。
<base> 标签为页面上的所有链接规定默认地址或默认目标。
通常情况下,浏览器会从当前文档的 URL 中提取相应的元素来填写相对 URL 中的空白。
使用 <base> 标签可以改变这一点。浏览器随后将不再使用当前文档的 URL,
而使用指定的基本 URL 来解析所有的相对 URL。
这其中包括 <a>、<img>、<link>、<form> 标签中的 URL。
--%>
<title>提交跳转页面的语法</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<form action="xgx82906.jsp" method="post">
用户名:<input type="text" name="username">
密码:<input type="password" name="pwd">
爱好:<input type="checkbox" value="game" name="like">游戏
<input type="checkbox" value="study" name="like">学习
<input type="checkbox" value="sing" name="like">唱歌
<input type="checkbox" value="say" name="like">聊天
<input type="submit">
</form>
</body>
</html>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
%>
<%
//设置请求编码格式
request.setCharacterEncoding("UTF-8");//传过来的信息,用utf-8转一下。
/* 在这里定义变量,接收前一个页面传过来的数据。
getParameter获取请求传递的参数
1、form表单传参
2、页面url直接传参,跟form表单的get请求方式一样
get请求传参:网址后面加?号,然后后面是参数列表,属性=属性值的方式&属性=属性值
http://localhost:8080/XGXWeb/xgx/xgx82906.jsp?username=sad&pwd=sda
3、密文形式传参(跟form表单的post请求方式一样,method="post",默认的是get请求方式。)
*/
String username = request.getParameter("username");
String pwd = request.getParameter("pwd");
//获取请求传送name相同的参数的value,返回一个数组,多选框的value中的值。
String[] likes=request.getParameterValues("like");
//得到用户的ip地址,
String ip=request.getRemoteAddr();
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>xgx82906的提交页面</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
用户名是:<%=username%>
<br> 密码是:<%=pwd%>
<br>
爱好:
<%
for(int i=0;i<likes.length;i++){
%>
<%=likes[i] %>
<%
}
%>
<br>
<%=ip %>
</body>
</html>