javascript嵌套java实现jsp
<%@ 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>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">
-->
</head>
<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>
</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%>">
<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">
-->
</head>
<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);//转发的代码
//转发不丢失数据,在服务器内部直接发送数据
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");//重定向的代码
//重定向丢失数据,因为需要客户端重新发送数据
}else{
// request.getRequestDispatcher("login.jsp").forward(request, response);
response.sendRedirect("login.jsp");
}
%>
</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%>">
<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">
-->
</head>
<body>
<%
String user = request.getParameter("username");
// String nick = (String)request.getAttribute("nickName");
String nick = (String)session.getAttribute("nickName");
session.getMaxInactiveInterval();
%>
<h1>欢迎[<%=user %>]登录</h1>
<h2>Welcome[<%=nick %>]</h2>
<a href="exit.jsp">退出</a>
</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%>">
<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">
-->
</head>
<body>
<%
session.invalidate();
%>
</body>
</html>
javascript嵌套java实现jsp的更多相关文章
- jsp页面:js方法里嵌套java代码(是操作数据库的),如果这个js 方法没被调用,当jsp页面被解析的时候,不管这个js方法有没有被调用这段java代码都会被执行?
jsp页面:js方法里嵌套java代码(是操作数据库的),如果这个js 方法没被调用,当jsp页面被解析的时候,不管这个js方法有没有被调用这段java代码都会被执行? 因为在解析时最新解析的就是JA ...
- Java基础——JSP(一)
一.JSP的由来 在很多动态网页中,绝大多部分内容是不变的,只有局部内容需要动态产生和改变.例如, 一个新闻的浏览次数,只有这个次数是动态改变的,而Servlet程序返回客户端的代码全是java程序动 ...
- 杂项-Java:JSP
ylbtech-杂项-Java:JSP 1.返回顶部 1. JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Micros ...
- 【历史】JavaScript和Java没啥关系!————JavaScript简史
文章的开始先上张图: 图片拍摄自北京图书大厦,代表着现在国内应该是绝大部分书店的现状--Javascript书籍放在Java类当中.甚至很多业内人也一直认为Javascript是Java语言在浏览器内 ...
- java web jsp学习笔记--概述-常用语法,指令,动作元素,隐式对象,域对象
JSP学习笔记 1.什么是jsp JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术.JSP/Servlet规范.JS ...
- 常见指令与功能介绍-java之JSP学习第二天(非原创)
文章大纲 一.JSP 指令二.JSP 动作元素三.JSP 隐式对象四.JSP 客户端请求五.JSP 服务器响应六.JSP HTTP 状态码七.JSP 表单处理八.JSP 过滤器九.JSP Cookie ...
- java:JSP(JSPWeb.xml的配置,动态和静态导入JSP文件,重定项和请求转发,使用JSP实现数据库的增删改查实例)
1.JSP的配置: <%@ page language="java" import="java.util.*" pageEncoding="UT ...
- java的JSP技术
java的JSP技术 [toc] 1.JSP简介 Jsp技术是用来开发java web的页面显示的,所有MVC模型里面的视图层,所以视图层的开发 jsp不是编程语言,三个英文是java server ...
- JavaScript和Java之间的关系
今天来简单而又详细地说说JavaScript和Java的关系. 开门见山总结性一句话,它们之间的关系 = 雷锋和雷峰塔之间的关系,换句话说:它们之间没什么关系. 但往往有不少初学者甚至中级者认为它们之 ...
随机推荐
- Ubuntu 16.04 安装垃圾清理工具 BleachBit
BleachBit 可以清理系统缓存文件, 清理磁盘垃圾. 首先下载最新版 deb安装包,默认下载到Downloads 中, 下载链接: https://www.bleachbit.org/downl ...
- 自己实现一个nullptr
一 具体实现 代码(c++) const class nullptr_t { public: template<class T> inline operator T*() const { ...
- 初窥css---包含一些概念和一些文字样式
初窥css CSS相关概念 全称是层叠式样式表.规定了html在网页上的显示样式.我们都知道css主要是负责装饰页面的,但是其实在HTML4之前,网页的样式与架构全部都是写在一起的,也是在HTML4之 ...
- Cookie Session和自定义分页
cookie Cookie的由来 大家都知道HTTP协议是无状态的. 无状态的意思是每次请求都是独立的,它的执行情况和结果与前面的请求和之后的请求都无直接关系,它不会受前面的请求响应情况直接影响,也不 ...
- Java的基本类型和包装类型
测试的JDK版本:java version "1.7.0_79".Java的9中基本类型:void.char.boolean.byte.short.int.long.float.d ...
- 使用队列实现栈(2)(Java)
class MyStack { private Queue q1; private Queue q2; public MyStack(int size) { this.q1 = new Queue(s ...
- jquery获取元素节点
常用到的知识点,在此记录,以便查阅 $('.test').parent();//父节点 $('.test').parents();//全部父节点 $('.test').parents('.test1' ...
- 转:eclipse 设置Java快捷键补全
1.打开Eclipse,点击" Window - Preferences"; 2. 在目录树上选择"Java——Editor——Content Assist", ...
- 解决SecureCRT无法连接虚拟机的问题
- Analysis Services features supported by SQL Server editions
Analysis Services (servers) Feature Enterprise Standard Web Express with Advanced Services Express w ...