web project 读取数据库内容问题
我想做一个查看自己的用户信息的功能,在主页面点一个<a href="viewaccount.do">View Account</a>连接,直接可以显示数据库中内容
链接页面:<a href="viewaccount.do">View Account</a>
web.xml配置:
<servlet>
<servlet-name>ViewAccountServlet</servlet-name>
<servlet-class>com.lu.servlet.VeiwAccountServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ViewAccountServlet</servlet-name>
<url-pattern>/viewaccount.do</url-pattern>
</servlet-mapping>
ViewAccountServlet.java:
public class ViewAccountServlet extends HttpServlet {
/**
*
*/
private static final long serialVersionUID = 1L;
@SuppressWarnings("unchecked")
protected void doGet(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {
// TODO Auto-generated method stub
resp.setContentType("text/html;charset=gb2312");
// 取出表单中用户输入的用户名
String username = request.getParameter("username");
System.out.println("=================>"+username);
// 取出表单中用户输入的密码
System.out.println("u能传?"+username);
PrintWriter pw=resp.getWriter();
HttpSession session = request.getSession();
session.setAttribute("username", username);
System.out.println("ok");
request.setAttribute("username", username);
String sql="select * from account where username='" + username + "';";
try {
Connection con=ConnectionManager.getConnection();
Statement stmt=con.createStatement();
ResultSet rsLogon = stmt.executeQuery(sql);
ArrayList a=new ArrayList();
while(rsLogon.next()){
String Username=rsLogon.getString("username");
String Telephone=rsLogon.getString("telephone");
String Email=rsLogon.getString("email");
Account m=new Account();
m.setUsername(Username);
m.setTelephone(Telephone);
m.setEmail(Email);
a.add(m);
}
// session.setAttribute("b", a);
resp.sendRedirect("viewaccount.jsp");
System.out.println("ok");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//
//pw.println(true);
//System.out.println("===pw==="+pw);
//resp.sendRedirect("success.jsp");
}
@SuppressWarnings("unchecked")
protected void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
PrintWriter pw=resp.getWriter();
String username = req.getParameter("username");
System.out.println("u能传过来吗?"+username);
HttpSession session = req.getSession();
session.setAttribute("username", username);
req.setAttribute("username", username);
String sql="select * from account where username='" + username + "';";
try {
Connection con=ConnectionManager.getConnection();
Statement stmt=con.createStatement();
ResultSet rsLogon = stmt.executeQuery(sql);
ArrayList a=new ArrayList();
while(rsLogon.next()){
String Username=rsLogon.getString("username");
String Telephone=rsLogon.getString("telephone");
String Email=rsLogon.getString("email");
Account m=new Account();
m.setUsername(Username);
m.setTelephone(Telephone);
m.setEmail(Email);
a.add(m);
}
// session.setAttribute("b", a);
resp.sendRedirect("showaccount.jsp");
System.out.println("ok");
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//pw.println(true);
//System.out.println("===pw==="+pw);
//resp.sendRedirect("success.jsp");
}
}
总是会出现以下问题,各位大虾帮我看一下哪里出错了?
信息: Marking servlet ViewAccountServlet as unavailable
2012-4-8 12:09:14 org.apache.catalina.core.ApplicationContext log
严重: Error loading WebappClassLoader
delegate: false
repositories:
/WEB-INF/classes/
----------> Parent Classloader:
org.apache.catalina.loader.StandardClassLoader@193a66f
com.lu.servlet.VeiwAccountServlet
java.lang.ClassNotFoundException: com.lu.servlet.VeiwAccountServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
2012-4-8 12:09:14 org.apache.catalina.core.StandardWrapperValve invoke
严重: Allocate exception for servlet ViewAccountServlet
java.lang.ClassNotFoundException: com.lu.servlet.VeiwAccountServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1360)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1206)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1083)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:806)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:129)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:286)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:583)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)
[解决办法]
VeiwAccountServlet 与 ViewAccountServlet , 一字之差,搞IT要细心,那个才是合理的,自己改过来再试试