求query()的帮助

来源:互联网 发布:永久域名发布网器 编辑:程序博客网 时间:2024/06/09 20:29

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.xml.registry.infomodel.User;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

public class UserServlet extends HttpServlet {

 private static final long serialVersionUID = 1L;

 public void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  this.doPost(request, response);

 }

 public void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  String method=request.getParameter("method");
  if(method==null){
   method="";
  }
  if(method.equals("login")){
   login(request, response);
  }

 }
 public void login(HttpServletRequest request, HttpServletResponse response)
 throws ServletException, IOException {
  request.setCharacterEncoding("UTF-8");
  String username=request.getParameter("username");
  String password=request.getParameter("password");

  String sql="select * from users where username=?,password=?";
  String params[]={username,password};
  QueryRunner qr=DBHelper.getQueryRunner();
  List list=null;
  User user=null;
  try {
   //list=(List)qr.query(sql, new BeanListHandler(User.class), params);
   list=(List)qr.query(sql, new BeanListHandler(User.class));
   } catch (SQLException e) {
   e.printStackTrace();
  }
   if(list!=null&&list.size()>0){
    user=(User)list.get(0);
    HttpSession session=request.getSession();
    session.setAttribute("user", user);
    request.getRequestDispatcher("/admin.jsp").forward(request, response);
   }else{
    request.setAttribute("message", "用户名或密码有误!请确认以后重新登录……");
    request.getRequestDispatcher("/login.jsp").forward(request, response);
   }
}

}
而login.jsp

<%@ page language="java" contentType="text/html;charset=UTF-8" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>login page</title>
<style type="text/css">
<!--
.STYLE1 {font-size: large}
-->
</style></head>

<body>
<p>用户登录</p>
<% String message=(String)request.getAttribute("message");
    if(message!=null){
    out.print("<font color='red'>"+message+"</font>");
    }
 %>
<br><br>
<form id="form1" name="form1" method="post" action="/blog/servlet/UserServlet">
<input type="hidden" name="method" value="login"/>
  <table width="311" border="0">
    <tr>
      <td width="90">用户名:</td>
      <td width="205"><label>
        <input name="username" type="text" id="username" />
      </label></td>
    </tr>
    <tr>
      <td>密码:</td>
      <td><label>
        <input name="password" type="password" id="password" />
      </label></td>
    </tr>
    <tr>
      <td><label>
        <input type="submit" name="Submit" value="提交" />
      </label></td>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
<p>&nbsp; </p>
</body>

</html>
出现了以下错误

java.lang.NoClassDefFoundError: javax/xml/registry/infomodel/User
cn.com.tang.blog.UserServlet.login(UserServlet.java:51)
cn.com.tang.blog.UserServlet.doPost(UserServlet.java:34)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

希望得到大家的帮助!谢谢!