加入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登录验证并显示信息的更多相关文章

  1. 玩转web之servlet(六)---session介绍及简单使用(登录验证中保存信息)

    在浏览器与服务器进行交互时,往往需要把涉及到的一些数据保存下来,这时就需要使用cookie或session进行状态管理. 这篇文章先来说说session怎么用,首先在servlet中创建一个sessi ...

  2. JavaBean组件<jsp:forward>动作<jsp:param>动作登录页面输入用户名和密码,然后进入检查页面判断是否符合要求,符合要求跳转到成功界面,不符合要求返回登录界面,显示错误信息。

    JavaBean组件 JavaBean组件实际是一种java类.通过封装属性和方法成为具有某种功能或者处理某个业务的对象. 特点:1.实现代码的重复利用.2.容易编写和维护.3.jsp页面调用方便. ...

  3. 使用 jQuery Ajax 异步登录,并验证用户输入信息(maven)

    使用 jQuery Ajax 异步登录,并验证用户输入信息(maven) 本篇内容: (1)上一篇是使用同步的请求实现登录,并由 Servlet 决定登陆后下一步做哪些事情,本篇使用 jQuery A ...

  4. Spring 笔记 -06- 从 MySQL 建库到 登录验证数据库信息(maven)

    Spring 笔记 -06- 从 MySQL 建库到 登录验证数据库信息(maven) 本篇和 Spring 没有什么关系,只是学习 Spring,必备一些知识,所以放在这里了. 本篇内容: (1)M ...

  5. WPF:验证登录后关闭登录窗口,显示主窗口的解决方法

    http://www.27ba.com/post/145.html WPF:验证登录后关闭登录窗口,显示主窗口的解决方法 最近想做一个基于Socket的通讯工具,想模仿QQ那样,需要先登录,登录成功后 ...

  6. Django电商项目---完成登录验证和用户中心(个人信息)day3

    登录验证的实现 背景说明: 用户在商品界面选择商品后,在点击购物车或者结算订单之前 需要完成用户的登录验证,这里用装饰器来完成   创建装饰器类: df_user/user_decorator.py ...

  7. 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% ...

  8. JavaWeb MySQL 实现登录验证

    0. 环境准备 项目创建: IDEA 创建 Servlet 项目详细步骤:https://www.jianshu.com/p/386a79d16e05 导入 MySQL 驱动包: Java MySQL ...

  9. ASP.NET MVC 登录验证

     好久没写随笔了,这段时间没 什么事情,领导 一直没安排任务,索性 一直在研究代码,说实在的,这个登录都 搞得我云里雾里的,所以这次我可能也讲得不是 特别清楚,但是 我尽力把我知道的讲出来,顺便也对自 ...

随机推荐

  1. 过滤掉combobox里名称相同的选项

    var pname = ""; $('#PartName').combobox({ reload: url, formatter: function (row) {//过滤comb ...

  2. css 字体不撑开默认块级元素问题

    问题原因是行高的元素没有随字体大小而改变,设置line-hight属性和字体同时变换

  3. org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter与org.apache.struts.dispatcher.FilterDispatcher是什么区别?

    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter与org.apache.struts.dispatcher.F ...

  4. WPF在XAML中Binding使用StringFormat属性

    1. 绑定Currency, 如果没有字符的话, =后面需要先加入{}. 不加的话会出问题. 1 <TextBlock Text="{Binding Amount, StringFor ...

  5. 爱奇艺招聘uwp开发

    招聘链接:https://job.cnblogs.com/offer/53380/ 工作地点:北京-海淀 工作年限:1年 学历要求:本科 招聘分类:移动开发工程师 工资范围:面议 职位要求 1.扎实的 ...

  6. 那些OVER的封装

    什么over什么,如pppoe, ppp的封装都在over对象之后,入下图: PPPOE   Ipsec

  7. Visual C#编写3D游戏框架示例

    你可能对实际地编写游戏代码期待已久了.由于DirectX SDK 2004年夏季更新包含了一个牢固的示例框架组件,并且它被设计成能在你自己的代码中直接使用,同时还为你处理了很多事务,所以你只要简单的使 ...

  8. python爬虫中文网页cmd打印出错问题解决

    问题描述 用python写爬虫,很多时候我们会先在cmd下先进行尝试. 运行爬虫之后,肯定的,我们想看看爬取的结果. 于是,我们print... 运气好的话,一切顺利.但这样的次数不多,更多地,我们会 ...

  9. C#操作JSON

    http://www.cnblogs.com/LiZhiW/p/3624729.html C#操作JSON 1. .NET对JSON的支持介绍............................. ...

  10. 如何清洗 Git Repo 代码仓库

    git prune 如何清洗 Git Repo 代码仓库       在腾讯云上创建您的SQL Cluster>>> »   相信不少团队的代码仓库 Git Repo 变得越来越大. ...