admin 管理员组文章数量: 887021
2024年1月17日发(作者:源程序又称为)
把JSP传数据的到JAVABEAN
jsp文件如下:
<%@ page contentType="text/html; charset=GBK" %>
<%@include file="" %>
Login
Login page!
javaBean文件如下:
package ;
import .*;
import tDatabase.*;
import .*;
public class UserBean extends ConnectDatabase{
private String userName;
private String password;
private Hashtable customList = new Hashtable();
public UserBean() {
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
rd = password;
}
public UserBean(String username, String password) {
me = username;
rd = password;
}
public void add(String username,String password){
ResultSet rs=null;
connect();
String sql="insert into customer values('',"+me+","+rd+")";
try{
rs=a(sql);
} catch (SQLException ex) {
}
}
/*public boolean check(){
int count=0;
connect();
String sql="select username,password from customer where username='"+me+"'
and password='"+rd+"'";
ResultSet rs=null;
try {
rs = a(sql);
if (()){
return true;
}
else{
return false;
}
}
catch (SQLException ex) {
return false;
}
}
*/
public boolean check(){
boolean re=true;
int count=0;
connect();
String sql="select count(*) as a from customer where username='"+userName+"' and
password='"+password+"'";
ResultSet rs=null;
try {
rs = a(sql);
if (()){
count=("a");
n(count);
}
if (count==0){
return false;
}
else{
return re;
}
}
catch (SQLException ex) {
return false;
}
}
public void remove(){
connect();
String sql="delete from customer where username='"+userName+"'";
try {
getdata(sql);
}
catch (SQLException ex) {
tackTrace();
}
diconnect();
}
public void update(){
connect();
String sql="update from customers set password='"+password+"'
username='"+userName+"'";
try {
getdata(sql);
}
catch (SQLException ex) {
tackTrace();
}
}
public String getUserName() {
return userName;
}
public void setUserName(String userName) {
where
me = userName;
}
}
Servlet文件如下:
package t;
import t.*;
import .*;
import .*;
import .*;
import an;
public class LoginServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=GBK";
//Initialize global variables
public void init() throws ServletException {
}
//Process the HTTP Post request
public void doPost(HttpServletRequest request, HttpServletResponse response)
ServletException, IOException {
// tentType(CONTENT_TYPE);
String username = ameter("username");
String password = ameter("password");
n("In the loginservlet!");
UserBean user=new UserBean(username,password);
if(()){
n(() );
HttpSession session=sion();
ribute("user",username);
direct("/");
}
else{
n("Login false,try again!");
direct("/");
}
}
}优惠促销打折网 5号仓库
throws
版权声明:本文标题:把JSP传数据的到JAVABEAN 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1705430477h484471.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论