首页 新闻 搜索 专区 学院

索引1超出范围 request.setatributte(用户名没有写入页面);

0
悬赏园豆:5 [已关闭问题] 关闭于 2015-07-09 19:12

**
* 服务端管理员试题类
* @author Administrator
*
*/
public class userserver {
private int sid;
private String sname;
private String spwd;

public userserver(int sid, String sname, String spwd) {
super();
this.sid = sid;
this.sname = sname;
this.spwd = spwd;
}

public int getSid() {
return sid;
}

public void setSid(int sid) {
this.sid = sid;
}

public String getSname() {
return sname;
}

public void setSname(String sname) {
this.sname = sname;
}

public String getSpwd() {
return spwd;
}

public void setSpwd(String spwd) {
this.spwd = spwd;
}

}

 

public class userserverdaoimpl implements serverdao {
private DBUtils db = new DBUtils();

public userserver userser(String sname,String spwd){

Object[] obj = {sname,spwd};
List<userserver> userserverlogin = db.queryForObject
("select * from server where sname = '?' and spwd = '?' ", obj, userserver.class);
if (userserverlogin.size() > 0) { //debug时走到这一行报索引 1超出范围
return userserverlogin.get(0);
}
else{
return null;
}

}
}

 


public class userserverservice {
private serverdao serdao = new userserverdaoimpl();
/**
* 获取服务端前台对象
* @param request 获取前台请求参数
* @return 返回一个前台用户对象
*/
public userserver getuserserver(HttpServletRequest request){
String sname = request.getParameter("sname");
String spwd = request.getParameter("spwd");
return new userserver(0, sname, spwd);
}
/**
* 判断服务端是否登录
* @param request 获取前台对象参数
* @return 返回一个结果
*/
public boolean userserverlogin(HttpServletRequest request){
boolean serverlog = false;
userserver userserver = getuserserver(request);
userserver userserv = serdao.userser(userserver.getSname(),userserver.getSpwd());
if(userserv != null){
serverlog = true;
request.setAttribute("server", userserv);
}
return serverlog;
}
}

 


public class userserverlet extends HttpServlet {

private static final long serialVersionUID = 5614879197433265L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
userservice user=new userservice();
userserverservice userser = new userserverservice();
String url=null;
int flag = Integer.valueOf(request.getParameter("flag"));
switch (flag) {
case 0://超级管理员登录
if(userser.userserverlogin(request)){
url = "server/serverindex.jsp";
}
break;
case 1://普通管理员登录

break;
case 2://普通用户注册
if (user.isreg(request)) {
url = "cilent/rigster.jsp";
}
break;
case 3://普通用户登录
if (user.islogin(request)) {
url = "cilent/loginuser.jsp";
}
break;
default:

break;
}
request.getRequestDispatcher(url).forward(request, response);
}
}

玉儿滢心的主页 玉儿滢心 | 初学一级 | 园豆:187
提问于:2014-10-30 14:52
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册