Struts2用action类从jsp中获取select中option的value值
3个回答
展开全部
jsp页面部分代码:
<s:form name="form1" method="post" action="glydenglu" namespace="/ssgl">
<select name="role" >
<option value="1">普通管理员</option>
<option value="2">系统管理员</option>
</select>
</s:form>
action类:
public class GlydengluAction extends ActionSupport {
private String role;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
public String denglu(){
HttpServletRequest request = ServletActionContext.getRequest();
String roles = request.getParameter("role");
if(rand_input.equals(rand)){
System.out.println(roles);
return SUCCESS;
}else{
return INPUT;
}
}
}
System.out.println(roles);打印出来的就是option的value值。
<s:form name="form1" method="post" action="glydenglu" namespace="/ssgl">
<select name="role" >
<option value="1">普通管理员</option>
<option value="2">系统管理员</option>
</select>
</s:form>
action类:
public class GlydengluAction extends ActionSupport {
private String role;
@Override
public String execute() throws Exception {
// TODO Auto-generated method stub
return super.execute();
}
public String denglu(){
HttpServletRequest request = ServletActionContext.getRequest();
String roles = request.getParameter("role");
if(rand_input.equals(rand)){
System.out.println(roles);
return SUCCESS;
}else{
return INPUT;
}
}
}
System.out.println(roles);打印出来的就是option的value值。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询