stuts 验证用户名登陆代码!

cuisichao 2010-07-13 10:56:24
public class textaction extends Action {

@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
String ward = null;
textform tf = (textform) form;
String mess = "";

Jdbc jdbc = new Jdbc();
Connection cot = (Connection) jdbc.getcon();
Statement st = null;
ResultSet rs = null;
List list = new ArrayList();
try {
st = cot.createStatement();
String sql = "select * from user";
// String sql = "select * from user where uname="+tf.getName();
rs = st.executeQuery(sql);
while (rs.next()) {
String aa = rs.getString(1);
list.add(aa);
}
if (tf.getName() != null && !"".equals(tf.getName())) {
for (int i = 0; i < list.size(); i++) {
if (!tf.getName().equals(list.get(i))
&& tf.getName() != list.get(i)) {
mess = "用户名错误";
request.setAttribute("mess", mess);
ward = "err";
System.out.println(ward + "111111111111111");
} else {
mess = "登入 ok.你登入的用户名";
request.setAttribute("mess", mess);
request.setAttribute("tf", tf);
request.setAttribute("list", list);
ward = "succ";
return mapping.findForward(ward);
}
}
}

else {
mess = "用户名为空";
request.setAttribute("mess", mess);
return mapping.findForward("err");
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
cot.close();
rs.close();
st.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println(ward);
return mapping.findForward(ward);
}
}
...全文
102 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
nigel_jun 2010-07-19
  • 打赏
  • 举报
回复
学习中......
leavin521 2010-07-19
  • 打赏
  • 举报
回复
学艺 ~~~~
QQ371496669 2010-07-19
  • 打赏
  • 举报
回复
请问楼主想干嘛呢?
niu90 2010-07-15
  • 打赏
  • 举报
回复
renjianguokeivor 2010-07-15
  • 打赏
  • 举报
回复
路过。。。
JavPer 2010-07-15
  • 打赏
  • 举报
回复
是晒代码,不看
bb5209027 2010-07-15
  • 打赏
  • 举报
回复
受教。。。
soft_newcoder 2010-07-13
  • 打赏
  • 举报
回复
好像不是问问题的……
-droidcoffee- 2010-07-13
  • 打赏
  • 举报
回复
study
neverloseming 2010-07-13
  • 打赏
  • 举报
回复
LZ想问啥?!

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧