操作步骤
1、在录入表单内录入1位长度的信息
2、提交后在action中取不到输入的长度是1的表单中的值录入条件:用户名录入汉字,密码输入1位字符,提交。代码附如下
==========================struts配置===========================
<struts-config>
<data-sources />
<form-beans>
<form-bean name="testForm" type="com.zhze.action.form.TestForm" /> </form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action attribute="testForm" name="testForm" path="/testAction"
type="com.zhze.action.action.TestActionAction">
<forward name="rtn" path="/test.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.zhze.action.ApplicationResources" />
</struts-config>
=========================action=======================
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TestForm testForm = (TestForm) form;// TODO Auto-generated method stub
System.out.println("密码是:" + testForm.getPassword());
request.setAttribute("name", testForm.getLogin());
request.setAttribute("pwd", testForm.getPassword());
return mapping.findForward("rtn");
}
=========================录入页========================
<html:form action="testAction.do" method="post" focus="login" >
<table border="0">
<tr>
<td>Login:</td>
<td><html:text property="login" /></td>
</tr>
<tr>
<td>Password:</td>
<td><html:text property="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
========================结果页==========================
用户:<%=request.getAttribute("name") %>
<br/>
密码:<%=request.getAttribute("pwd") %>
<br/>
此处密码是空!
1、在录入表单内录入1位长度的信息
2、提交后在action中取不到输入的长度是1的表单中的值录入条件:用户名录入汉字,密码输入1位字符,提交。代码附如下
==========================struts配置===========================
<struts-config>
<data-sources />
<form-beans>
<form-bean name="testForm" type="com.zhze.action.form.TestForm" /> </form-beans>
<global-exceptions />
<global-forwards />
<action-mappings>
<action attribute="testForm" name="testForm" path="/testAction"
type="com.zhze.action.action.TestActionAction">
<forward name="rtn" path="/test.jsp" />
</action>
</action-mappings>
<message-resources parameter="com.zhze.action.ApplicationResources" />
</struts-config>
=========================action=======================
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
TestForm testForm = (TestForm) form;// TODO Auto-generated method stub
System.out.println("密码是:" + testForm.getPassword());
request.setAttribute("name", testForm.getLogin());
request.setAttribute("pwd", testForm.getPassword());
return mapping.findForward("rtn");
}
=========================录入页========================
<html:form action="testAction.do" method="post" focus="login" >
<table border="0">
<tr>
<td>Login:</td>
<td><html:text property="login" /></td>
</tr>
<tr>
<td>Password:</td>
<td><html:text property="password" /></td>
</tr>
<tr>
<td colspan="2" align="center"><html:submit /></td>
</tr>
</table>
</html:form>
========================结果页==========================
用户:<%=request.getAttribute("name") %>
<br/>
密码:<%=request.getAttribute("pwd") %>
<br/>
此处密码是空!
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
// 有条件地选择设置字符编码使用
if (ignore || (request.getCharacterEncoding() == null)) { String encoding = this.encoding; if (encoding != null) {
//当执行此代码后,即取不到1位值,大于1位时可以取到。
request.setCharacterEncoding(encoding);
}
}
}
这个是过滤器。