jsp调用struts,jsp调用action,action获取表单提交的参数
自定义action类。LgqAction:
@Component
@Scope(value="prototype")
public class LgqAction {
private Connection conn = null;
private PreparedStatement pstmt = null;
private ResultSet rs = null;
public String execute(){
return "successa";
// return "input";
}
public String mystruts(){
// return "success";
return "56";
}
}
1、创建action
<action name="lgqname" class="com.ssh.action.LgqAction" method="mystruts">
<result name="success" type="chain">user</result>
<result name="56">/lgqstrutsjsp.jsp</result>
</action>
<action name="formtest" class="com.ssh.action.LoginAction" >
<result name="56">/lgqjsp.jsp</result>
</action>
jsp调用struts之action——表单,<a>标签
<a href="lgqname">myaction</a><br>
<form action="<%=basePath%>formtest" >
<input type="text" name="username"/>
<input type="text" name="password"/>
<input class="continue" type="submit" value="登录">
</form>
2、action获取表单提交的参数
(1)创建对应name标签方法
private String username;
public String getUsername(){
return username;
}
public void setUsername(String username){
this.username = username;
}
运行get即可赋值进username
(2)HttpServletRequest方法
HttpServletRequest reqeust= ServletActionContext.getRequest();
String username2=reqeust.getParameter("username");//字符串
(3)ActionContext、Map方法
ActionContext context = ActionContext.getContext();
Map params = context.getParameters();
Object username3=params.get("username")+"我的obj";