admin 管理员组

文章数量: 887021


2024年1月17日发(作者:源程序又称为)

把JSP传数据的到JAVABEAN

jsp文件如下:

<%@ page contentType="text/html; charset=GBK" %>

<%@include file="" %>

</p><p style="text-indent: 2em;";>Login </p><p style="text-indent: 2em;";>

Login page!

yourname:

password:

 

Register

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


本文标签: 称为 打折 源程序