<%@ 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的更多相关文章

  1. jsp页面:js方法里嵌套java代码(是操作数据库的),如果这个js 方法没被调用,当jsp页面被解析的时候,不管这个js方法有没有被调用这段java代码都会被执行?

    jsp页面:js方法里嵌套java代码(是操作数据库的),如果这个js 方法没被调用,当jsp页面被解析的时候,不管这个js方法有没有被调用这段java代码都会被执行? 因为在解析时最新解析的就是JA ...

  2. Java基础——JSP(一)

    一.JSP的由来 在很多动态网页中,绝大多部分内容是不变的,只有局部内容需要动态产生和改变.例如, 一个新闻的浏览次数,只有这个次数是动态改变的,而Servlet程序返回客户端的代码全是java程序动 ...

  3. 杂项-Java:JSP

    ylbtech-杂项-Java:JSP 1.返回顶部 1. JSP全名为Java Server Pages,中文名叫java服务器页面,其根本是一个简化的Servlet设计,它是由Sun Micros ...

  4. 【历史】JavaScript和Java没啥关系!————JavaScript简史

    文章的开始先上张图: 图片拍摄自北京图书大厦,代表着现在国内应该是绝大部分书店的现状--Javascript书籍放在Java类当中.甚至很多业内人也一直认为Javascript是Java语言在浏览器内 ...

  5. java web jsp学习笔记--概述-常用语法,指令,动作元素,隐式对象,域对象

     JSP学习笔记 1.什么是jsp JSP全称是Java Server Pages,它和servle技术一样,都是SUN公司定义的一种用于开发动态web资源的技术.JSP/Servlet规范.JS ...

  6. 常见指令与功能介绍-java之JSP学习第二天(非原创)

    文章大纲 一.JSP 指令二.JSP 动作元素三.JSP 隐式对象四.JSP 客户端请求五.JSP 服务器响应六.JSP HTTP 状态码七.JSP 表单处理八.JSP 过滤器九.JSP Cookie ...

  7. java:JSP(JSPWeb.xml的配置,动态和静态导入JSP文件,重定项和请求转发,使用JSP实现数据库的增删改查实例)

    1.JSP的配置: <%@ page language="java" import="java.util.*" pageEncoding="UT ...

  8. java的JSP技术

    java的JSP技术 [toc] 1.JSP简介 Jsp技术是用来开发java web的页面显示的,所有MVC模型里面的视图层,所以视图层的开发 jsp不是编程语言,三个英文是java server ...

  9. JavaScript和Java之间的关系

    今天来简单而又详细地说说JavaScript和Java的关系. 开门见山总结性一句话,它们之间的关系 = 雷锋和雷峰塔之间的关系,换句话说:它们之间没什么关系. 但往往有不少初学者甚至中级者认为它们之 ...

随机推荐

  1. Scrapy框架-Spider

    目录 1. Spider 2.Scrapy源代码 2.1. Scrapy主要属性和方法 3.parse()方法的工作机制 1. Spider Spider类定义了如何爬取某个(或某些)网站.包括了爬取 ...

  2. windows本地远程虚拟机docker中的数据的问题

    关闭各种防火墙 打开宿主机(windows)的cmd,在其中添加通往192.168.1.0/24网络的路由. 通往192.168.1.0/24网络的数据包由172.20.1.12来转发 route a ...

  3. SkiaSharp图像处理

    SkiaSharp图像处理 .NET Core使用skiasharp文字头像生成方案(基于docker发布)   一.问题背景 目前.NET Core下面针对于图像处理的库微软并没有集成,在.NET ...

  4. day11(函数参数,函数对象,打散机制,函数嵌套调用)

    一,复习 # 什么是函数:具体特定功能的代码块 - 特定功能代码块作为一个整体,并给该整体命名,就是函数 # 函数的优点: # 1.减少代码的冗余 # 2.结构清晰,可读性强 # 3.具有复用性,开发 ...

  5. C#-之属性(2)

    1.   属性结合字段和方法得多个方面,对于对象的用户来说,属性就像字段(这样就可以修改属性值或者访问),对于类的实现者来说,属性包括两个各部分get访问器(用于读取属性)和set访问器(用于设置属性 ...

  6. sudo: no tty present and no askpass program specified

    sudo: no tty present and no askpass program specified | 学步园 https://www.xuebuyuan.com/2157339.html 通 ...

  7. npm install报错

    npm ERR!    C:\Users\xxxxxx\AppData\Roaming\npm-cache\_logs\2019-02-27T07_48_47_283Z-debug.log " ...

  8. P3373 【模板】线段树 2

    线段树的模板,但是还应注意维护乘标记,乘法的优先级大于加法,一定记得还要取模. #include<bits/stdc++.h> using namespace std; ; struct ...

  9. Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock32 error was 14: curl#6 - "Could not resolve host: mirrorlist.centos.org; Unknown error"

     今天安装完带图形界面的CentOS 7后,在Terminal中运行yum安装命令时报了以下错误: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 ...

  10. squid3.5缓存代理实践记录

    准备: 两台服务器,一台web,一台squid缓存代理 squid机域名:www.dannylinux.top web机IP:12.1.1.1 1.版本: [root@danny squid]# sq ...