问题描述
急,急,急!请高手指点指点啊,十分感谢!(如何在servlet中调用bean,);<编译servlet时提示找不到BaseDao?>bean程序如下:packagetest;importjava.sql.*;importjavax.naming.Context;importjavax.naming.InitialContext;publicclassBaseDao{Connectioncon;Statementsmt;ResultSetrs;publicConnectiongetConnection()throwsException{try{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");con=DriverManager.getConnection("jdbc:odbc:xinbener");smt=con.createStatement();}catch(Exceptione){e.printStackTrace();}returncon;}publicvoidexec(Stringsql){try{getConnection();smt.executeUpdate(sql);}catch(Exceptione){e.printStackTrace();}}publicResultSetgetResultSet(Stringsql){try{getConnection();rs=smt.executeQuery(sql);returnrs;}catch(Exceptione){e.printStackTrace();returnnull;}}}servlet程序如下:packagetest;importjavax.servlet.ServletException;importjavax.servlet.http.HttpServlet;importjavax.servlet.http.HttpServletRequest;importjavax.servlet.http.HttpServletResponse;importjavax.servlet.http.HttpSession;importjava.io.*;importjava.sql.*;publicclassdengServletextendsHttpServlet{publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{doPost(request,response);}publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{try{response.setContentType("text/html;charset=GB2312");PrintWriterout=response.getWriter();Stringguanli=request.getParameter("guanli");Stringxuehao=getname(request.getParameter("xue"));Stringname=getname(request.getParameter("username"));BaseDaobd=newBaseDao();Stringsql="select*fromxinbenerwhere字段2='"+name+"'and字段1='"+xuehao+"'";ResultSetrs=bd.getResultSet(sql);if(rs.next()){HttpSessionsession=request.getSession(true);session.setAttribute("name",name);if(guanli.equals("b")){request.getRequestDispatcher("/shou.html").forward(request,response);}else{request.getRequestDispatcher("/shou1.html").forward(request,response);}}else{out.print("<scriptlanguage='javascript'>window.alert('亲爱的用户"+name+",确认该用户是否存在!')</script>");out.print("<scriptLanuage='JavaScript'>window.location='denglu.html'</script>");}rs.close();}catch(Exceptione){thrownewServletException(e.toString());}}publicStringgetname(StringStr){try{byteb[]=Str.getBytes("ISO-8859-1");Str=newString(b);}catch(Exceptionee){ee.printStackTrace();}returnStr;}};