我的struts-config.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" " http://struts.apache.org/dtds/struts-config_1_2.dtd">
<struts-config>
<data-sources />
<form-beans >
<form-bean name="loginForm" type="org.apche.struts.action.DynaActionForm">
<form-property name="petId" type="java.lang.String" ></form-property>
<form-property name="petPassword" type="java.lang.String"></form-property>
<form-property name="valiCode" type="java.lang.String"></form-property>
</form-bean>
</form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action path="/login" type="epet.form.PetAction" name="loginForm" scope="request" parameter="operate" >
<forward name="index" path="/index.jsp"></forward>
<forward name="Detail" path="/WEB-INF/pet/petInfo.jsp"></forward>
</action>
</action-mappings>
<message-resources parameter="com.epetWeb.struts.ApplicationResources" />
</struts-config>
PetAction中获取代码数据如下:
DynaActionForm forms=(DynaActionForm)form; [~~~~~~~~~~~测试forms获取为null]
Integer petId=null;
String petPassword=null;
String valiCode=null;
String sessionCode=null;
try{
petId=Integer.parseInt(forms.getString("petId"));
petPassword=forms.getString("petPassword");
valiCode=forms.getString("valiCode");
................................................
前台index.jsp
宠物<input type="text" name="petId" size="6" />
密码<input type="password" name="petPassword" size="6" />
验证码<input type="text" name="valiCode" size="4" />
<img src="vcode.jsp" />
<button onclick="javascript:doLogin();">登录</button>
<br /><html:errors property="login" />