JavaBean里面能不能直接拿到JSP里面的request对象,就像servlet的那样(50分)

  • 主题发起人 主题发起人 donyad
  • 开始时间 开始时间
D

donyad

Unregistered / Unconfirmed
GUEST, unregistred user!
偶写的处理类
借口还得把request.getParament("SELECT")这样的东西传进去
嘎烦哦
 
可以,
比如jsp里写:
bbsuser.login(uname,upass,request);
javabean里写:
public int login(String username, String userpassmd5,
HttpServletRequest request) { //论坛登陆
this.strDBURL = "jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ=" +
request.getRealPath("/") + "WEB-INF//mybbs.mdb";
try {
com.mypackage.mybbs.dbbean db = new com.mypackage.mybbs.dbbean(this.
strJDBCDriverName, this.strDBURL, "", "");
db.connect();
db.setStrSQL("select * from bbsuser where username=/'" + username +
"/' and userpass=/'" + userpass + "/'");
//");
//
db.excuteQuery();
this.setSqlRst(db.getSqlRst());
if (this.sqlRst != null) {
if (sqlRst.next()) {
System.out.println("你的用户名字是:/t" + sqlRst.getString("username"));
System.out.println("你的密码是:/t" + sqlRst.getString("userpass"));
System.out.println("一共有" + sqlRst.getRow() + "条记录<br>");
this.username = username;
this.userpass = userpass;
this.userVerify = "true";
return 1;
//1表示登陆成功
}
catch (SQLException ex) {
return 0;
//表示登陆失败
}
}
 
哦?
“HttpServletRequest”当servlet那样写么?
servlet还没写过,try-try看
但是偶的javax下面没有servlet这个类
郁闷中
import不了包进来
能顺便把这个问题也答了么?
多谢
 
给一个tomcat5带的例子
<jsp:useBean id="cart" scope="session" class="sessions.DummyCart" />
<jsp:setProperty name="cart" property="*" />
<%
cart.processRequest(request);
%>
------------------
package sessions;
import javax.servlet.http.*;
import java.util.Vector;
import java.util.Enumeration;
public class DummyCart {
Vector v = new Vector();
String submit = null;
String item = null;
private void addItem(String name) {
v.addElement(name);
}
private void removeItem(String name) {
v.removeElement(name);
}
public void setItem(String name) {
item = name;
}

public void setSubmit(String s) {
submit = s;
}
public String[] getItems() {
String[] s = new String[v.size()];
v.copyInto(s);
return s;
}

// reset
private void reset() {
//submit = null;
//item = null;
}
public void processRequest(HttpServletRequest request) {
if (submit == null)
addItem(item);
if (submit.equals("add"))
addItem(item);
else
if (submit.equals("remove"))
removeItem(item);
// reset at the end of the request
reset();
}
}
 
多人接受答案了。
 
后退
顶部