login.java///////////////////////////////////////////////////////////////////////////////////////////////////
public class Login extends ActionSupport {
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
if (isInvalid(username) || isInvalid(password)) {
msg = "用户名或者密码不能为空";
return INPUT;
}
if (null == new UserDAO().checkAccount(username, password)) {
msg = "用户名或者密码错误";
return INPUT;
}
String userid = new UserDAO().checkAccount(username, password);
HttpSession session = ServletActionContext.getRequest().getSession();
session.setAttribute("userid", userid);
//list = new LendDAO().matureBook(Integer.parseInt(userid));
return SUCCESS;
}
public String getMsg() {
return msg;
} public void setMsg(String msg) {
this.msg = msg;
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
public String checkAccount(String account, String password) {
String sql = "SELECT ConNumber FROM Consumer WHERE ConNumber=? AND ConPass=?";
PreparedStatement pstat = null;
ResultSet rs = null;
Connection conn = new DBHelper().getConn();
String userid = null;
try {
pstat = conn.prepareStatement(sql);
pstat.setString(1, account);
pstat.setString(2, password);
rs = pstat.executeQuery();
while (rs.next()) {
userid = rs.getString(1);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
try {
if (pstat != null)
pstat.close();
if (conn != null)
conn.close();
if (rs != null)
rs.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return userid; }
login.jsp/////////////////////////////////////////////////////////////////////////////////////////////////<%@ page contentType="text/html;charset=GBK" language="java"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
... ... ...
... ... ...(省略)
</s:form>
</p>
</table>
<table width="30%" align="center">
<tr>
<td class="STYLE1">
<s:property value="msg"/>
</td>
</tr>
</table>
</body>请问 我输入了错误的密码 但是按钮下面的标签 为什么不出现相应的错误提示呢? 是不是少写了什么呢?还有是不是没有导入相应的包呢?谢谢。

解决方案 »

  1.   

    以下红色部分你配置了吗??
    <action name="" class="">
       <result name="input">错误视图</result>
       <result>成功视图</result>
    </action>
      

  2.   

    struts.xml ......
    <package name="action" extends="struts-default">
    <action name="Login" class="action.Login">
    <result name="input"  type="redirect">/login.jsp</result>......
    这么的。。请问有错么。
      

  3.   

    <result name="input"  type="redirect">/login.jsp </result>type="redirect" 发生错误。把它去掉或者写type="dispatcher"。type="redirect"即发生重定向,所有请求参数值都消失,这就是你的错误信息没有显示的原因。
      

  4.   

    result type不写,默认为dispatcher。