<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<script type="text/javascript" src="../js/jquery-1.7.2.js"></script>
<script type="text/javascript">
$(function(){
$(":button").click(function(){
document.getElementsByTagName("form")[0].submit();
}); })
</script>
<body>
<form action="../loginSrevlet" method="post">
用户名:<input type="text" name="userName"/><br/>
密码:<input type="password" name="password"/><br/>
<button type="button">登录</button>
<button type="reset">重置</button>
</form>
</body>
</html>
 package com.zdsofe.servlet1;

 import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List; import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession; /**
* Servlet implementation class loginSrevlet
*/
@WebServlet("/loginSrevlet")
public class loginSrevlet extends HttpServlet {
private static final long serialVersionUID = 1L; /**
* @see HttpServlet#HttpServlet()
*/
public loginSrevlet() {
super();
// TODO Auto-generated constructor stub
} /**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
} /**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//编码格式
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/heml charset=utf-8"); //得到表单的数据
Enumeration<String > name=request.getParameterNames();
List<String> list=new ArrayList<String>();
while(name.hasMoreElements())
{
list.add(request.getParameter(name.nextElement()));
} //创建Session对象
HttpSession ss= request.getSession();
ss.setAttribute("uName", list.get(0));
response.sendRedirect("/webProject1/jsp/loginWelcome.jsp"); } }
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- 实现3秒后跳转功能-->
<!-- <meta content="3;url=loginBottom.jsp" http-equiv="refresh"> -->
<title>Insert title here</title>
</head>
<body>
<%=session.getAttribute("uName") %>
<button onclick="location.href='loginBottom.jsp'">跳转</button>
三秒后跳转....
</body>
</html>
 <%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
Welcome!
</body>
</html>

session的用法的更多相关文章

  1. thinkPHP中session()方法用法详解

    本文实例讲述了thinkPHP中session()方法用法.分享给大家供大家参考,具体如下: 系统提供了Session管理和操作的完善支持,全部操作可以通过一个内置的session函数完成. 用法 ? ...

  2. 数据库的修改和删除;比较标签代替<,>,=号;模板替换;session的用法

    注: 1.session:系统默认开启;用途:防止跳过登录(只能访问登录方法);session和cookie的用法(手册->专题); 赋值:session('name','value'); 取值 ...

  3. Session,ViewState用法

      基本理论: session值是保存在服务器内存上,那么,可以肯定,大量的使用session将导致服务器负担加重. 而viewstate由于只是将数据存入到页面隐藏控件里,不再占用服务器资源,因此, ...

  4. session cookie用法

    1.session(1)session存储在服务器的(2)session每个人存一份(3)session有默认的过期时间(4)session里面可以存储任意类型的数据安全,对服务造成压力用法:1.当一 ...

  5. C#中Session的用法详细介绍

    Session模型简介 在学习之前我们会疑惑,Session是什么呢?简单来说就是服务器给客户端的一个编号.当一台WWW服务器运行时,可能有若干个用户浏览正在运正在这台服务器上的网站.当每 个用户首次 ...

  6. session 的用法

    </head> <body> <?php //session_start();//开启session,必须写在PHP代码最顶端 //HTTP,无状态性 //记录登陆者状态 ...

  7. php里session的用法

    PHP中的session默认情况下是使用客户端的Cookie.当客户端的Cookie被禁用时,会自动通过Query_String来传递. Php处理会话的函数一共有11个,我们详细介绍一下将要用到几个 ...

  8. php 中cookie和session的用法比较

    1.cookie数据存放在客户的浏览器上,session数据放在服务器上. 2.cookie不是很安全,别人可以分析存放在本地的COOKIE并进行COOKIE欺骗,考虑到安全应当使用session. ...

  9. JSF session的用法

    http://blog.csdn.net/finelife/article/details/1608632 1.写入sessionObject sessionName = "name&quo ...

随机推荐

  1. Error creating bean with name 'signController': Injection of autowired dependencies failed

    出现了一大串错误,Error creating bean with name 'signController': Injection of autowired dependencies failed. ...

  2. asp.net core 教程(七)-异常处理、静态文件

    Asp.Net Core-异常处理 Asp.Net Core-异常处理 在这一章,我们将讨论异常和错误处理.当 ASP.NET Core应用程序中发生错误时,您可以以各种不同的方式来处理.让我们来看看 ...

  3. [转] .NET领域驱动设计—初尝(疑问、模式、原则、工具、过程、框架、实践)

    阅读目录: 1.1.疑问 1.1.1.UML何用 1.1.2.领域建模 1.2.模式 1.3.原则 1.5.过程 1.6.框架 1.7.项目演示 最近在研究DDD颇有收获,所以整理出来跟大家分享,共同 ...

  4. mysqldump 用法总结

    mysqldump 备份 备份数据库 my_database $ mysqldump -uUSER -pPASSWD my_database > my_database.sql 备份数据库 my ...

  5. Cordova各个插件使用介绍系列(二)—$cordovaBarcodeScanner扫描二维码与生成二维码

    详情链接地址:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/cordova-2-cordovabarcodescanner/ 这是 ...

  6. DB2简介和安装部署

    一.DB2相关概念 1.DB2体系结构: DB2体系结构中的最高一层是系统,一个系统表示DB2的一个安装.在由很多机器组成 的网络环境中,我们有时=也称系统为数据库分区,一个系统可以包含多个DB2实例 ...

  7. js中的事件,内置对象,正则表达式

    [JS中的事件分类] 1.鼠标事件: click/dbclick/mouseover/mouseout/mousemove/mousedown/mouseup 2.键盘事件: keydown: 键盘按 ...

  8. 12.js如何将明文转为MD5

    1.先下载MD5.JS 2.引入,使用hex_md5(str)即可

  9. kindeditor使用入门-张国红

    kindeditor是在线编辑器,比较好用,以下是使用这个插件的步骤. 下载kindeditor-4.1.10.zip 解压 asp,asp.net,php对于jsp开发没有用,可以删除 新建web工 ...

  10. 极简单的方式序列化sqlalchemy结果集为JSON

    继承 json.JSONEncoder 实现一个针对sqlalchemy返回类型的处理方式. sqlalchemy的返回类型有大都有两种,一种是Model对象,一种是Query集合(只查询部分字段). ...