日期:2014-05-17  浏览次数:20709 次

用button来submit
javascript代码
  <script type="text/javascript">
  function Submit(arg0){
alert(arg0);
alert("clientSubmit".equal(arg0));
document.formlogin.action = "Login.action";
document.formlogin.submit();
}
</script>

index.jsp相关代码:
<form method="post" action="" name="formlogin">
  <table>
  <tr><td>用户名:</td></tr>
  <tr><td><input type="text" name="username"/></td></tr>
  <tr><td>密码:</td></tr>
  <tr><td><input type="password" name="password"/></td></tr>
  <tr><td><input type="button" name="clientSubmit" value="个人登录" onclick="javascript:Submit(this.name)"/></td></tr>
  <tr><td><input type="button" name="adminSubmit" value="管理登录" onclick="javascript:Submit(this.name)"/></td></tr>
  </table>  
  </form>

struts.xml相关代码:
<struts>
  <package name="com.LostAndFound.myaction" extends="struts-default">
  <action name="Login" class="com.LostAndFound.myaction.LoginAction">
  <result name="success">/pages/client/clientMainPage.jsp</result>
  <result name="input">/index.jsp</result>
  </action>
  </package>
</struts>


LoginAction代码:
public class LoginAction implements Action{
private String username = "";
private String password = "";

public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute() throws Exception {
// TODO Auto-generated method stub
return "success";
}

}

为什么按button会没反应?我觉得应该能转到clientMainPage.jsp的,没看出有什么错呀?这样的怎么调呢?
查了好久,好难啊!!

------解决方案--------------------
alert("clientSubmit".equal(arg0));
把这一句去掉试试。