Struts 做的 登陆和注册页面
注册 ,不能判断用户名是否成在
登陆,不管 输入什么密码和名字,都可以登陆?
详细问题加QQ 我不在乎送多少分 关键是谁能帮我解决问题!!!代码太长了就不贴了!

解决方案 »

  1.   

    你在你的ACTION方法里面跟踪下,然后了解下struts的导航应该就可以了
      

  2.   

    Dao
    public void denglu(DengForm f ) {
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet rs = null;
    String sql = "select * from login3 where user=? and passwd1=?";

    try {
    conn = ds.getConnection();
    stmt =conn.prepareStatement(sql);
    rs=stmt.executeQuery();


    stmt.setString(2, f.getName());
    stmt.setString(3,f.getPasswd1());
    rs.next();

    if(rs.next()){
    rs.getString(2);
    }

    } catch (Exception err) {
    err.printStackTrace(); } finally {
    if (rs != null)
    try {
    rs.close();
    } catch (Exception ee) {
    }
    if (stmt != null)
    try {
    stmt.close();
    } catch (Exception ee) {
    }
    if (conn != null)
    try {
    conn.close();
    } catch (Exception ee) {
    }
    }

    }
      

  3.   

    Action public class DengAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
    HttpServletRequest request, HttpServletResponse response) {
    DengForm dengForm = (DengForm) form;// TODO Auto-generated method stub
    zhuce1 zhu1 = new zhuce1();
    zhuce z = new zhuce(getDataSource(request, "database"));

    String sl1 = null;

    if(form instanceof DengForm){
    z.denglu(dengForm);}
    if(zhu1.getName()==dengForm.getName()){


    return mapping.findForward("chenggong");
    }else{
    return mapping.findForward("shibai");
    }
    } }  FormBean 
    ublic class DengForm extends ActionForm {
    /*
     * Generated fields
     */ /** passwd1 property */
    private String passwd1="passwd1"; /** name property */
    private String name="name"; /*
     * Generated Methods
     */ /** 
     * Method validate
     * @param mapping
     * @param request
     * @return ActionErrors
     */
    public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request) {
    // TODO Auto-generated method stub
    return null;
    } /** 
     * Method reset
     * @param mapping
     * @param request
     */
    public void reset(ActionMapping mapping, HttpServletRequest request) {
    // TODO Auto-generated method stub
    } /** 
     * Returns the passwd1.
     * @return String
     */
    public String getPasswd1() {
    return passwd1;
    } /** 
     * Set the passwd1.
     * @param passwd1 The passwd1 to set
     */
    public void setPasswd1(String passwd1) {
    this.passwd1 = passwd1;
    } /** 
     * Returns the name.
     * @return String
     */
    public String getName() {
    return name;
    } /** 
     * Set the name.
     * @param name The name to set
     */
    public void setName(String name) {
    this.name = name;
    }
    }
    帮我 看看哪里有问题 
      

  4.   

    这是登陆页面
    <%@ page contentType="text/html;charset=gb2312" %><%@ taglib uri="http://jakarta.apache.org/struts/tags-bean" prefix="bean" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-logic" prefix="logic" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-tiles" prefix="tiles" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-template" prefix="template" %>
    <%@ taglib uri="http://jakarta.apache.org/struts/tags-nested" prefix="nested" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html:html locale="true">  <head>
        <html:base />    
        <title>denglu.jsp</title>
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
      </head>  
     <body>
        <html:form action="/deng" method="post" >
        <center><font color=red>${}</font></center>
        <hr>
          <table border="0">
            
              姓名:<input type="" name="name">
             密码:<input type="" name="passwd1">
            
            
            
             <td colspan="2" align="center"><html:submit /></td>
            </tr>
          </table>
        </html:form>
      
      </body>
    </html:html>
      

  5.   

    "   <html:form action="/deng" method="post" >"?
    你的CONFIG.XML文件呢?
    报的错也贴下
      

  6.   

    TO LZ:First of all, i have to say that u have no talent in this. However, some hard work might help. Anyway, may god bless uThe problem was caused as you lost the information in your DAO whether or not the result set has next rows.Your DAO should tell your Action whether this user's login is OK or failed in the following aspects: 
    1. the user exsits or not (rs.next())
    2. the user's id/name and password match or not (form.password.equals(rs.getString(..)))Besides, there are still so many mistakes in your codes, especially in JDBC.regards
      

  7.   

    if(rs.next()){
      rs.getString()
    } form.password.equals(rs.getString(..))
    DAO里你在仔细看看  整理清楚
    这个你懂以后你会上一个新台阶的
    祝福你 1取值问题
    2你那成功和失败页面不知道你写了没
      

  8.   

    stmt.setString(2, f.getName());
    stmt.setString(3,f.getPasswd1());
    rs.next();

    if(rs.next()){
    rs.getString(2);
    } 应该使这里错误 下面还没看呢
      

  9.   

    rs.next();

    if(rs.next()){
    rs.getString(2);
    }这个有问题吧
    if(rs.next()){
    rs.getString(2);
    }
      

  10.   

    rs=stmt.executeQuery();


    stmt.setString(2, f.getName());
    stmt.setString(3,f.getPasswd1());为什么是从2开始的呢?这个地方好像是有问题。。可以把这个位置换成
    stmt.setString(1, f.getName());
    stmt.setString(2,f.getPasswd1());
    rs=stmt.executeQuery();
    试一下。希望能够帮助你
      

  11.   

    XML配置文件
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd"><struts-config>
      <data-sources >
          <data-source key="database">
             <set-property property="password" value="" />
             <set-property property="minCount" value="1" />
             <set-property property="maxCount" value="20" />
             <set-property property="user" value="root" />
             <set-property property="driverClass" value="com.mysql.jdbc.Driver" />
             <set-property property="description" value="" />
             <set-property property="url" value="jdbc:mysql://localhost:3306/user_login" />
             <set-property property="readOnly" value="false" />
             <set-property property="autoCommit" value="true" />
             <set-property property="loginTimeout" value="10000" />
          </data-source>  </data-sources>
      
      
      <form-beans >
        <form-bean name="yanzhengForm" type="com.yourcompany.struts.form.YanzhengForm" />
      <form-bean name="dengluForm" type="com.yourcompany.struts.form.dengluForm" />
        <form-bean name="dengForm" type="com.yourcompany.struts.form.DengForm" />
        <form-bean name="deleteForm" type="com.yourcompany.struts.form.DeleteForm" />

      </form-beans>  <global-exceptions />
      <global-forwards />
      <action-mappings >
        <action
          attribute="yanzhengForm"
          input="/zhuce.jsp"
          name="yanzhengForm"
          path="/yanzheng"
          scope="request"
          type="com.yourcompany.struts.action.YanzhengAction">
          <forward name="chenggong" path="/chenggong.jsp" />
          <forward name="shibai" path="/shibai.jsp" />
        </action>
        <action
          attribute="dengForm"
          input="/denglu.jsp"
          name="dengForm"
          path="/deng"
          scope="request"
          type="com.yourcompany.struts.action.DengAction">
          <forward name="chenggong" path="/chenggong.jsp" />
          <forward name="shibai" path="/shibai.jsp" />
        </action>
        <action
          attribute="deleteForm"
          input="/delete.jsp"
          name="deleteForm"
          path="/delete"
          scope="request"
          type="com.yourcompany.struts.action.DeleteAction"
          validate="false">
          <forward name="chenggong" path="/chenggong.jsp" />
          <forward name="shibai" path="/shibai.jsp" />
        </action>
        
        
          </action-mappings>  <message-resources parameter="com.yourcompany.struts.ApplicationResources" />
    </struts-config>
      

  12.   

    在登录的页面里,
              姓名:<input type="" name="name">
             密码:<input type="" name="passwd1">不用input,用<html:text property="name" />和<html:password property="passwd1" />
    另外,你的formBean要有name和passwd1这2个属性,还要有setter和getter方法。
    在struts-config里面对formbean和action的设置也要注意。
      

  13.   

    你的这个地方绝对用问题,
    if(zhu1.getName()==dengForm.getName()){看见没有,你比较两个字符串,不能用==去比较,必须用equals去比较,就没有问题了。
      

  14.   

    小弟也认为这个地方有问题!if(zhu1.getName()==dengForm.getName()){........}
    必须用equals去比较。==比较出的结果总是false。
      

  15.   

    对字符比较串比较不能用==,要用equals
      

  16.   

    应该是先
    stmt.setString(2, f.getName());
    stmt.setString(3,f.getPasswd1());
    完了在
    rs = stmt.executeQuery();
    还有就是字符串比较 应该用equals 
    ==比的是引用 而equals 比的是字符串的内容