单选按钮组radio中value值为汉字的问题

ljs_forest1984 ljs_forest1984 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
问题描述:
1.输入login.jsp为为标准的html,其中用到了两个单选按钮组userType和sex,前一个取值为英文,后一个取值为中文,并在其中用struts:if标签对这两个值进行了判断。页面的代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="/struts-tags" prefix="struts" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>

<title>My JSP 'login.jsp' starting page</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">

</head>

<body>
<form name="form" method="post" action="loginPerson.action">
account<input type="text" name="account" value="" /><br>
password<input type="password" name="password" value="" /><br>
<input type="radio" name="userType" value="examinee" checked /> 考生
<input type="radio" name="userType" value="administrator" /> 管理员 <br>
<input type="radio" name="sex" value="男" /> 男
<input type="radio" name="sex" value="女" /> 女 <br>
<input type="submit" value="submit" />
<input type="reset" value="reset" />
</form>

<struts:if test="#request.sex == '男'">checked 男</struts:if>
<struts:if test="#request.sex == '女'">checked 女</struts:if>

<struts:if test="#request.userType == 'examinee'">checked examinee</struts:if>
<struts:if test="#request.userType == 'administrator'">checked administrator</struts:if>
</body>
</html>

2.在服务器层将login.jsp发回来后,userType 的值能正确判断,但sex的值却判断不成功。

3.struts 的action代码很简单,不做任务处理,直接返回登录页面:
public class LoginAction extends ActionSupport {
private String account;
private String password;
private String userType;
private String sex;

//getter and setter省略

public String execute() {
System.out.println(userType + " , " + account + " , " + password + " , " + sex);
return "login";
}
}

struts.xml配置为:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="main" extends="struts-default">
<global-results>
<result name="login">/login.jsp</result>
</global-results>
<action name="loginPerson" class="com.bcb.action.LoginAction">
<result name="success">/welcome.jsp</result>
</action>
</package>
</struts>

问题:两个单选按钮组userType和sex,前一个取值为英文,后一个取值为中文,取值英文的判断成功了,但取值中文的却判断失败了。这是在项目开发中遇到的问题,折腾了一天了,为了表达清楚,才做了这么一个小例子,请大家看看是什么原因?在线等答案!
...全文

相关推荐

评论 11
收藏 已收藏
分享
返回顶部
ljs_forest1984
Web 开发 81,108 成员 341,721 内容