<%@ 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" >
<base href= "<%=basePath%>" >
<title>my JSP ' index.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" >
-
<body onload= "Ready ()" >
<script>
function Ready () {
<%cookie[] cookies = request.getcookies ();
for (int i = 0; i < cookies.length; i++) {
String key = Cookies[i].getname ();
String value = Cookies[i].getvalue ();
if (key! = null && key.equals ("username")) {
%>
document.getElementById ("username"). value= "<%=value%>";
<%
}
if (key! = null && key.equals ("password")) {
%>
document.getElementById ("password"). value= "<%=value%>";
<%
}
}
%>
}
</script>
<form name= "F1" id= "F1" action= "check.jsp" method= "POST" >
<table>
<tr>
<td>Username:</td>
<td><input type= "text" name= "username" id= "username" ></td>
</tr>
<tr>
<td>Password:</td>
<td><input type= "password" name= "password" id= "password" ></td>
</tr>
<tr>
<TD colspan= "2" ><input type= "Submit" ></td>
</tr>
</table>
</form>
</body>
<%@ 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" >
<base href= "<%=basePath%>" >
<title>my JSP ' index.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" >
-
<body>
<%
Request.setattribute ("info", "abc");
Request.setattribute ("User", new OBJ ());
String info = (string) request.getattribute ("info");
obj user = (obj) request.getattribute ("User");
String username = request.getparameter ("username");
String Password = request.getparameter ("password");
if (Username.equals ("Adiwood") && password.equals ("Ilovejapan")) {
Request.setattribute ("nickname", "James");
Session.setattribute ("nickname", "Smith");
Session.setmaxinactiveinterval (5);
Request.getrequestdispatcher ("main.jsp"). Forward (request, response);//Forwarding Code
Forwards no data loss, sending data directly inside the server
Cookie UC = new Cookie ("username", username);
Cookie PC = new Cookie ("password", password);
Uc.setmaxage (60*60*24*7);
Pc.setmaxage (3600*24*7);
Response.addcookie (UC);
Response.addcookie (PC);
Response.sendredirect ("main.jsp");//redirect Code
REDIRECT lost data because the client needs to resend the data
}else{
Request.getrequestdispatcher ("login.jsp"). Forward (request, response);
Response.sendredirect ("login.jsp");
}
%>
</body>
<%@ 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" >
<base href= "<%=basePath%>" >
<title>my JSP ' index.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" >
-
<body>
<%
String user = Request.getparameter ("username");
String nick = (string) request.getattribute ("nickname");
String nick = (string) session.getattribute ("nickname");
Session.getmaxinactiveinterval ();
%>
<a href= "exit.jsp" > Exit </a>
</body>
<%@ 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" >
<base href= "<%=basePath%>" >
<title>my JSP ' index.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" >
-
<body>
<%
Session.invalidate ();
%>
</body>
JavaScript nested Java Implementation JSP