| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 520 人关注过本帖
标题:[求助] 很急,麻烦版主快点答复,不好意思了!
只看楼主 加入收藏
猫猫三
Rank: 1
等 级:新手上路
帖 子:39
专家分:0
注 册:2006-5-7
收藏
 问题点数:0 回复次数:2 
[求助] 很急,麻烦版主快点答复,不好意思了!
[求助] 很急,麻烦版主快点答复,不好意思了!

表单的内容就如下面这样,其它的省了:
<tr>
<td><span class="style2">选择身份:</span></td>
<td><select size="1" name="select">
<option value="a" selected>管理员</option>
<option value="b">总经理</option>
<option value="c">员工</option>
</select></td>
</tr>
验证页我是用 MyEclipe 弄的,,叫 "servlet".......代码如下:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class servlet extends HttpServlet {

/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

//获取也面数据
String userName = "";
String userPwd = "";
userName = request.getParameter("txtUserName");
userPwd = request.getParameter("txtUserPwd");
System.out.println("1 " + userName + " " + userPwd);


// 进行数据读取判断
Connection conn = null;

PreparedStatement ps = null;

ResultSet rs = null;
try {
Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
String url = "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=pubs";
//pubs为你的数据库的
String user = "sa";
String password = "123";
conn = DriverManager.getConnection(url,user,password);



String sql = "";

//执行查询
sql = "SELECT name, pwd FROM [user]";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();

if (rs.next()) {
System.out.println(rs.getString(1) + "@@@@" + rs.getString(2));
if (userName.equals(rs.getString(1).trim()) && userPwd.equals(rs.getString(2).trim())) {

response.sendRedirect("index.jsp");
} else {
response.sendRedirect("error.jsp");
}
}



} catch (ClassNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (null != rs) {
rs.close();
}

if (null != ps) {
ps.close();
}

if (null != conn) {
conn.close();
}

} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

}
怎么再写另外的代码 使得 可以从表单的 select 获取数据!谢谢!我数据库里面是用 Flag=0\1\2做标记!

搜索更多相关主题的帖子: 版主 麻烦 答复 
2006-05-25 17:01
铲铲
Rank: 7Rank: 7Rank: 7
等 级:贵宾
威 望:34
帖 子:506
专家分:0
注 册:2006-5-2
收藏
得分:0 

这是Java代码,恕我知识储备不足,无法解答你的问题


铲铲是也
2006-05-26 09:17
jhy
Rank: 1
等 级:新手上路
帖 子:185
专家分:0
注 册:2006-4-25
收藏
得分:0 
贴错地了。。。

Your future depends on your dreams !
2006-05-26 16:12
快速回复:[求助] 很急,麻烦版主快点答复,不好意思了!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.041722 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved