日期:2014-05-20  浏览次数:20672 次

struts1.X关于表单提交时action执行两次的问题
今天写一个简单的登录功能,代码如下:
//=================================================================================
//============================ index.jsp =========================================
//=================================================================================
<%@ page language="java" contentType="text/html;charset=GBK"%>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
  <base href="<%=basePath%>">
   
  <title>Welcome to myweb</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">
-->
<script type="text/javascript">
function login()
{
  loginForm.submit();
}
</script>
  </head>
  
  <body>&nbsp;  
  This is my JSP page. <br>
  <html:form action="login?methods=login" method="POST">
  u:<html:text property="userName"></html:text><br/>
  p:<html:password property="passWord"></html:password>
  </html:form>
  <html:button property="s" value="submitform" onclick="login()"/>
  </body>
</html>


//=================================================================================
//======================= struts-config.xml ======================================
//=================================================================================
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE struts-config PUBLIC
  "-//Apache Software Foundation//DTD Struts Configuration 1.3//EN"
  "http://struts.apache.org/dtds/struts-config_1_3.dtd">
<struts-config>
<display-name>display-name</display-name>
<description>myweb</description>
<form-beans>
<form-bean name="loginForm" type="com.myweb.bean.LoginForm" />
</form-beans>
<global-exceptions />
<global-forwards>
<forward name="error" path="/error.jsp" />
</global-forwards>

<action-mappings>
<action name="loginForm" parameter="methods"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="request" validate="false" path="/login">
<forward name="login" path="/info/main.jsp" />
</action>
</action-mappings>

<controller />

<message-resources parameter="application.properties" />

<plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation"
value="/WEB-INF/actionContext.xml" />