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 登录验证
好久没写随笔了,这段时间没 什么事情,领导 一直没安排任务,索性 一直在研究代码,说实在的,这个登录都 搞得我云里雾里的,所以这次我可能也讲得不是 特别清楚,但是 我尽力把我知道的讲出来,顺便也对自 ...
随机推荐
- VS2013无法启动 IIS Express Web解决办法
不要勾选[覆盖应用程序根URL(U)],或让[覆盖应用程序根URL(U)]下面的输入框和上面的输入框的地址一样! 使用VS2013有一段时间了,因前期都是编写C/S程序,没有使用到B/S调试器.前几日 ...
- 手机中点击链接或button按钮出现黄色边框的解决办法
a,input,button{outline: none; -webkit-tap-highlight-color: rgba(255, 255, 255, 0); -webkit-focus-rin ...
- Mac 使用SSH远程登录
一.打开ssh Mac Terminal是自带SSH的,可以用whereis来看看: $ whereis ssh 但是在现有进程中找不到ssh对应的进程: $ ps aux | grep ssh ap ...
- 【Asp.Net】Asp.Net CommandName作用
数据绑定控件的模板中 CommandName 属性以下属性值会触发特定的事件: Cancel(取消) Delete(删除) Select(选择) Edit(编辑) Insert(插入) Update( ...
- C语言 位运算
1G=1024M; 1M=102KB; 1KB=1024B(字节); 1B=8bits(位); #include<stdio.h> #include<stdlib.h> //C ...
- OpenCV人脸检测demo--facedetect
&1 问题来源 在运行官网的facedetect这个demo的时候,总是不会出来result的图形,电脑右下角提示的错误是“显示器驱动程序已停止响应,而且已恢复 windows 8(R)”. ...
- TCP建立连接、断开连接以及正常报文的报头和报位的大小
正常通信报文大小: 以太网的头尾:14字节 IP首部:20字节 TCP首部:20字节 尾部4字节校验 合计:58 三次握手的报文大小: SYN: 70 AYN,ACK:72 ACK: 64 合计:20 ...
- 学习bash
工作8年,前6年基本是Windows环境下,也就是个鼠标党:两年前换工作开始用linux,也就开始了领略了命令行的强大,无论是直接在命令行组合命令,也还写几行简单的shell脚本,其能完成的功能往往令 ...
- nodeJs--模块module.exports与实例化方法;
在nodejs中,提供了exports 和 require 两个对象,其中 exports 是模块公开的接口,require 用于从外部获取一个模块的接口,即所获取模块的 exports 对象.而在e ...
- Jenkins进阶系列之——03parameterized-trigger插件
说明:这个插件可以根据已经完成构建的结果,触发新Job或者传递参数. 官方说明:Parameterized Trigger Plugin 安装步骤: 系统管理→管理插件→可选插件→Build Trig ...