java ee 做一个简单的登陆界面和数据库连接的程序

@WebServlet("/DbBean.do")public class DbBean extends HttpServlet implements Serializable {private String jdbcUrl="jdbc:mysql://localhost:3306/gossip";private String username="root";private String password="123456";private final String USERS = "E:/eclipse/eclipse/workspace/12345/users";private final String SUCCESS_VIEW1 = "member1.view";private final String SUCCESS_VIEW2 = "member2.view";private final String ERROR_VIEW = "index.html";public DbBean(){ try{ Class.forName("com.mysql.jdbc.Driver"); }catch(ClassNotFoundException ex){ throw new RuntimeException(ex);}}public void doPost(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException{ Statement statement = null; Connection conn = null; SQLException ex = null; String user = request.getParameter("user"); String pass = request.getParameter("pass"); String page = ERROR_VIEW; try { conn=DriverManager.getConnection(jdbcUrl, username, password); statement=conn.createStatement(); String u=statement.executeQuery("select name,pwd from t_account where name='"+ user +"' and pwd='"+pass+"'").toString(); if(u=="0"){page=ERROR_VIEW;} if(u=="1"&&user=="user"){page=SUCCESS_VIEW1;} if(u=="1"&&user=="admin"){page=SUCCESS_VIEW2;} response.sendRedirect(page); } catch (SQLException e) {ex = e;} finally { if (statement != null) { try {statement.close();} catch(SQLException e) { if(ex == null) {ex = e;}}} if (conn != null) {try {conn.close();} catch(SQLException e) { if(ex == null) {ex = e;}}} if(ex != null) {throw new RuntimeException(ex);}}}}<div id="loginPanel"> <div> <img src='images/caterpillar.jpg' alt='Gossip 微网志'/> </div> <p> <form method='post' action='DbBean.do'> <table bgcolor='#cccccc'> <tr> <td colspan='2'>会员登录</td><tr> <td>名称:</td> <td><input type='text' name='user'></td> </tr> <tr><td>密码:</td> <td><input type='password' name='pass'></td> </tr> <tr> <td colspan='2' align='center'><input type='submit' value='登入'></td></tr> </table> </form></div><div></div></body></html>
在运行html文件后,显示

第1个回答  2015-06-24
很明显 路径错误 如果是启动了tomcat就出现这个错误 你检查一下是不是web.xml配置错了
第2个回答  2015-06-24
路径错误。
第3个回答  2015-06-24
你是用什么工具部署这个项目的?tomcat启动了?

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网