当前位置: 代码迷 >> Java Web开发 >> 登入帐号验证,其后根据帐号查询字段跟帐号相关的值,但帐号值过不过来。
  详细解决方案

登入帐号验证,其后根据帐号查询字段跟帐号相关的值,但帐号值过不过来。

热度:53   发布时间:2016-04-16 22:25:03.0
登入帐号验证,然后根据帐号查询字段跟帐号相关的值,但帐号值过不过来。。


这是验证的
<%@ page language="java" contentType="text/html;charset=gb2312"
 pageEncoding="UTF-8"%>
<%@ page import="java.sql.*"%>
<%@ page import="java.util.*"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
 <head>
  <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>
  <div align=center>
  <%
   //获取用户名
   String sUserName = request.getParameter ( "txtUserName" );
   //获取密码
   String sPasswd = request.getParameter ( "txtPassword" );
   //登记JDBC驱动程序
  
     Class.forName("com.mysql.jdbc.Driver");//加载oracle类
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/nysql", "root", "");
   //SQL语句
   String sql = "select * from userinfo where username='" + sUserName
     + "' and userpwd = '" + sPasswd + "'";
   Statement stmt = conn.createStatement ( );
   ResultSet rs = stmt.executeQuery ( sql ); //返回查询结果
   //如果记录集非空,表明有匹配的用户名和密码,登陆成功
   if ( rs.next ( ) )
   {
       response.sendRedirect("zhigong_select.jsp");
   } else
   //否则登录失败
   {
    out.println ( "用户名不存在或密码错误!" );
   }
 
  %>
  </div>
 </body>
</html>


这是查询

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%request.setCharacterEncoding("UTF-8"); %>
<%@page import="java.sql.*"%>
<%@page import="java.sql.Statement"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.DriverManager"%>
<%
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 '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>
<%
try {

Class.forName("com.mysql.jdbc.Driver");//加载oracle类
Connection conn = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/nysql", "root", "");
    String a = request.getParameter("id");
String b = request.getParameter("name");
String c = request.getParameter("work");
String d = request.getParameter("workday");
String e = request.getParameter("Remarks");
String f = request.getParameter("status");
String g = request.getParameter("review_name");
String h = request.getParameter("review_time");
String sUserName = request.getParameter ( "txtUserName" );
String wzx1 = "select *from huibao where id ="+sUserName+"";

            Statement hy = conn.createStatement();
    ResultSet jg = hy.executeQuery(wzx1);//结果集类型??

out.println("<table border='2' bordercolor='blue' cellspacing='0' style=\"table-layout:fixed\">");
out.println("<tr> <td align='center' width='40px'>编号</td><td style='text-align:center;width:100px'>姓名</td> <td  style='text-align:center;width:80px'>工作</td> <td  style='text-align:center;width:100px'>工作日期 </td><td align='center'>汇报</td> "
  相关解决方案