JSP登录验证并显示信息
加入C标签:
加入jstl.jar 和standard.jar加入Lib文件夹中
将c.tld放入WEB-Info文件夹中
index.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>
<style>
#div
{
position:absolute;
left:20%;
top:10%;
}
</style>
<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>
<div id="div">
<form action="Login" method="post">
名字:<input type="text" name="uname" id="uname"/>
<br>
密码:<input type="password" name="upwd" id="upwd"/>
<br>
请选择自己喜欢的颜色:
<br>
<input type="radio" name="color" value="红色" />红色
<input type="radio" name="color" value="绿色" checked />绿色
<input type="radio" name="color" value="绿色" />蓝色
<br>
选择喜欢的运动:
<br>
<input type="checkbox" name="checkbox" value="篮球"/>篮球
<input type="checkbox" name="checkbox" value="足球"/>足球
<input type="checkbox" name="checkbox" value="乒乓球"/>乒乓球
<br>
选择需要睡觉的时间:<select name="utime">
<option value="7小时">7小时</option> <option value="8小时">8小时</option> <option value="9小时">9小时</option>
</select>
<br>
个人简介:
<br>
<textarea name="ps" id="ps" rows="10" cols="30"></textarea>
<br>
<input type="submit" />
<input type="reset"/>
</form>
</div>
</body>
</html>
welcome.jsp:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <!-- 加入JSTL标签-->
<%
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 'welcome.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>
你的用户名是: ${uname} <!-- EL表达式 -->
密码是: ${upwd}
<br>
你喜欢的颜色是:${color} <br>
你喜欢的运动是:
<c:forEach items="${ch}" var="ch"> <!-- C标签 -->
${ch}
</c:forEach>
<br>
需要睡觉的时间
${utime}
<br>
个人简介
${ps}
</body>
</html>
新建一个servlet包,建一个Login.java文件
package servlet;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class Login extends HttpServlet{
public void doGet(HttpServletRequest request,HttpServletResponse response)
{
response.setCharacterEncoding("UTF-8");
try {
request.setCharacterEncoding("UTF-8");
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
String uname=request.getParameter("uname");//获取数据
request.setAttribute("uname", uname); //设值
String upwd=request.getParameter("upwd");
request.setAttribute("upwd", upwd);
String color=request.getParameter("color");
request.setAttribute("color", color);
String ps=request.getParameter("ps");
request.setAttribute("ps", ps);
String utime=request.getParameter("utime");
request.setAttribute("utime", utime);
String checkbox[]=request.getParameterValues("checkbox");
request.setAttribute("ch", checkbox);
if(uname.equals("admin")&&upwd.equals("123"))
{
try {
request.getRequestDispatcher("welcome.jsp").forward(request, response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} else
try {
response.sendRedirect("index.jsp");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)
{
this.doGet(request, response);
}
public void destory()
{
super.destroy();
}
}
Web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>Login</servlet-name>
<servlet-class>servlet.Login</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Login</servlet-name>
<url-pattern>/Login</url-pattern>
</servlet-mapping>
<display-name></display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
JSP登录验证并显示信息的更多相关文章
- 玩转web之servlet(六)---session介绍及简单使用(登录验证中保存信息)
在浏览器与服务器进行交互时,往往需要把涉及到的一些数据保存下来,这时就需要使用cookie或session进行状态管理. 这篇文章先来说说session怎么用,首先在servlet中创建一个sessi ...
- JavaBean组件<jsp:forward>动作<jsp:param>动作登录页面输入用户名和密码,然后进入检查页面判断是否符合要求,符合要求跳转到成功界面,不符合要求返回登录界面,显示错误信息。
JavaBean组件 JavaBean组件实际是一种java类.通过封装属性和方法成为具有某种功能或者处理某个业务的对象. 特点:1.实现代码的重复利用.2.容易编写和维护.3.jsp页面调用方便. ...
- 使用 jQuery Ajax 异步登录,并验证用户输入信息(maven)
使用 jQuery Ajax 异步登录,并验证用户输入信息(maven) 本篇内容: (1)上一篇是使用同步的请求实现登录,并由 Servlet 决定登陆后下一步做哪些事情,本篇使用 jQuery A ...
- Spring 笔记 -06- 从 MySQL 建库到 登录验证数据库信息(maven)
Spring 笔记 -06- 从 MySQL 建库到 登录验证数据库信息(maven) 本篇和 Spring 没有什么关系,只是学习 Spring,必备一些知识,所以放在这里了. 本篇内容: (1)M ...
- WPF:验证登录后关闭登录窗口,显示主窗口的解决方法
http://www.27ba.com/post/145.html WPF:验证登录后关闭登录窗口,显示主窗口的解决方法 最近想做一个基于Socket的通讯工具,想模仿QQ那样,需要先登录,登录成功后 ...
- Django电商项目---完成登录验证和用户中心(个人信息)day3
登录验证的实现 背景说明: 用户在商品界面选择商品后,在点击购物车或者结算订单之前 需要完成用户的登录验证,这里用装饰器来完成 创建装饰器类: df_user/user_decorator.py ...
- Linux登录验证机制、SSH Bruteforce Login学习
相关学习资料 http://files.cnblogs.com/LittleHann/linux%E4%B8%AD%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95%E8%AE% ...
- JavaWeb MySQL 实现登录验证
0. 环境准备 项目创建: IDEA 创建 Servlet 项目详细步骤:https://www.jianshu.com/p/386a79d16e05 导入 MySQL 驱动包: Java MySQL ...
- ASP.NET MVC 登录验证
好久没写随笔了,这段时间没 什么事情,领导 一直没安排任务,索性 一直在研究代码,说实在的,这个登录都 搞得我云里雾里的,所以这次我可能也讲得不是 特别清楚,但是 我尽力把我知道的讲出来,顺便也对自 ...
随机推荐
- 啊D工具语句 适合Access和Mssql注入
啊D注入工具中使用的SQL注入语句 爆user )) )= | ***** ?Id)) : ?Id : Id 检查SA权限:)))) 爆当前库: )) -- 检查是否为mssql数据库:and exi ...
- Windows Phone:自定义字体在xaml和代码中使用
最近,我的小应用<认字>更新了一个能发声的版本,朋友对Speech做读音没有兴趣,反而对其中使用的楷体文字表示了兴趣,也许Speech的文章比较多,这次我对这个自定义字体在xaml和代码中 ...
- drbd初探及Heartbeat+DRBD+MySQL
1,drbd快速入门 http://www.mingxiao.info/article/?id=39#__RefHeading___Toc1114_501652171 2.Heartbeat+DRBD ...
- Linux Linux程序练习七
题目:实现两个程序mysignal.mycontrl,mycontrl给mysignal发送SIGINT信号,控制mysignal是否在屏幕打印“hello”字符串. //捕捉信号 #include ...
- C语言 百炼成钢9
//题目25:求1+2!+3!+...+20!的和 #define _CRT_SECURE_NO_WARNINGS #include<stdio.h> #include<stdlib ...
- SQLServer如何删除字段中的某个字符串,或者替换为空格?
sql="update Table set 字段=REPLACE ( 字段,'123' , ' ') where XXX条件"把字段中123替换为空格
- python 线性回归示例
说明:此文的第一部分参考了这里 用python进行线性回归分析非常方便,有现成的库可以使用比如:numpy.linalog.lstsq例子.scipy.stats.linregress例子.panda ...
- 学习笔记——Maven 命令行选项
2014-10-09:更新裁剪反应堆具体用法 说明: 1.使用-选项时,和后面的参数之间可以不要空格.而使用--选项时,和后面的参数之 间必须有空格.如下面的例子: $ mvn help:des ...
- 【原创】基于Memcached 实现用户登录的Demo(附源码)
一个简单的Memcached在Net中运用的一个demo.主要技术 Dapper+MVC+Memcached+sqlserver, 开发工具为vs2015+Sql 效果图如下: 登录后 解决方案 主要 ...
- 【Lucene实验1】构建索引
一.实验名称:构建索引 二.实验日期:2013/9/21 三.实验目的: 1) 能理解Lucene中的Document-Field结构的数据建模过程: 2) 能编针对特定数 ...