2018.3.7李锦浩【连续第148天】
今天学习forward动作,格式:<jsp:forward page=”URL”/>
这个动作得到的效果等同于request.getRequestDispatcher(“/url”).forward(request,response);
附:
<%@ page language="java" import="java.util.*"pageEncoding="utf-8"%>
<%
Stringpath = request.getContextPath();
StringbasePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'login.jsp' starting page</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>
<h1>系统登录</h1>
<hr>
<form name="loginForm"action="Forward_action.jsp" method="post">
<table>
<tr>
<td>用户名</td>
<td><input type="text"name="username" value=""/></td>
</tr>
<tr>
<td>密码</td>
<td><input type="password"name="password" value=""/></td>
</tr>
<tr>
<td colspan="2"align="center"><input type="submit"value="登录"/></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" import="java.util.*"pageEncoding="utf-8"%>
<%
Stringpath = request.getContextPath();
StringbasePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'include_command.jsp' startingpage</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>
<h1>forward动作</h1>
<hr>
<jsp:forward page="dologin.jsp"/>
<!-- request.getRequestDispatcher("dologin.jsp").forward(request,response) -->
</body>
</html>
<%@ page language="java" import="java.util.*"pageEncoding="utf-8"%>
<%
Stringpath = request.getContextPath();
StringbasePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTDHTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'dologin.jsp' starting page</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>
<h1>用户资料</h1>
<hr>
<%
request.setCharacterEncoding("utf-8");
String username="";
String password="";
if(request.getParameter("username")!=null){
username=request.getParameter("username");
}
if(request.getParameter("password")!=null){
password=request.getParameter("password");
}
%>
用户名:<br>
密码:<br>
</body>
</html>
明日任务:继续学习javaweb。