前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >JSP+JDBC

JSP+JDBC

作者头像
week
发布2018-08-27 10:32:51
2240
发布2018-08-27 10:32:51
举报
文章被收录于专栏:用户画像

login.jsp

代码语言:javascript
复制
<%@ 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>登陆界面</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>
    <form action="validate.jsp" method="post">
    	用户登录<br>
    	姓名:<input type="text" name="username"/><br>
    	密码:<input type="text" name="pswd"/><br>
    	<input type="submit" value="登录"/>
    </form>
  </body>
</html>

validate.jsp

代码语言:javascript
复制
<%@ page language="java" import="java.util.*" pageEncoding="utf-8" import="java.sql.*" %>
<jsp:useBean id="MySqlBean" scope="page" class="edu.qdgxy.jdbc.MySQLConnBean" />
<%
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 'validate.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">
	
  </head>
  
  <body>
  	<%
  		String username=request.getParameter("username");
  		String pswd=request.getParameter("pswd");
  		boolean validated=false;
  		String sql="select * from user";
  		MySqlBean.OpenConn();
  		ResultSet rs=MySqlBean.executeQuery(sql);
  		while(rs.next()){  			
  			if((rs.getString("username").compareTo(username)==0)&&(rs.getString("pswd").compareTo(pswd)==0)){
  				validated=true;
  			}
  		}
  		rs.close();
  		MySqlBean.closeStmt();
  		MySqlBean.closeConn();
  		if(validated){
  	 %>
   <jsp:forward page="welcome.jsp"/>
   		<%
   			}
   			else{
   		%>
   		<jsp:forward page="error.jsp"/>
   		<% 
   			}
   		 %>
  </body>
</html>

MySQLConnBean.java请参考http://blog.csdn.net/jxq0816/article/details/20442603

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2014年03月04日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档