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

@WebServlet("/DbBean.do")publicclassDbBeanextendsHttpServletimplementsSerializable{pr... @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文件后,显示
展开
 我来答
来自吴兴寺心花怒放的芙蓉玉
2015-06-24 · TA获得超过105个赞
知道小有建树答主
回答量:261
采纳率:100%
帮助的人:130万
展开全部
很明显 路径错误 如果是启动了tomcat就出现这个错误 你检查一下是不是web.xml配置错了
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
春山昳0gF
2015-06-24 · TA获得超过626个赞
知道小有建树答主
回答量:1258
采纳率:71%
帮助的人:240万
展开全部
路径错误。
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
11无敌队长
2015-06-24 · TA获得超过167个赞
知道小有建树答主
回答量:380
采纳率:50%
帮助的人:70.5万
展开全部
你是用什么工具部署这个项目的?tomcat启动了?
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式