我的html文件中有一个非常简单的单选按钮:
<form role="form" method="post" action="jsp/site/Portal.jsp?page=mypage">
<input type="radio" id="radio_1" name="name_radio" value="value1" />
<input type="radio" id="radio_2" name="name_radio" value="value2" />
<button name="action_validateForm" type="submit">
Valider
</button>
</form>
但是当我发送表格时,它会进入功能:
@Action( ACTION_VALIDATE_FORM )
public Page doValidateForm( HttpServletRequest request )
{
String valueGet = request.getParameter( "name_radio" );
if ( valueGet.equals( "value1" ) )
{
//Do action
}
else if ( valueGet.equals( "value2" ) )
{
//Do other action
}
}
问题在于,当我检查request.getParameter( "name_radio" )
时,无论我在确认表单之前选择的单选按钮,该值始终为false。怎么可能?它应该是value1,value2还是null?
答案 0 :(得分:1)
我认为您需要添加提交按钮或javascript代码来提交表单,然后尝试在JSP中获取单选按钮值。
看我添加了提交按钮。
<form role="form" method="post" action="jsp/site/Portal.jsp?page=mypage">
<input type="radio" id="radio_1" name="name_radio" value="value1" />
<input type="radio" id="radio_2" name="name_radio" value="value2" />
<button type="submit" value="Submit">Submit</button>
</form>