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";
?
總結
以上是生活随笔為你收集整理的jsp调用struts,jsp调用action,action获取表单提交的参数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 《金字塔原理》学习笔记
- 下一篇: Wampserver之 virtualH