struts中的action是单态的
来源:互联网 发布:吉利金刚里程表算法 编辑:程序博客网 时间:2024/05/17 04:52
一 action特性
action是单态的,包括ActionServlet。
单态是指:在整个程序运行过程中,始终是一个对象。
二 action单态特性证明
1 LoginAction
package com.cakin.actions;
//这是一个action(表示小队长,需要继承Action)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import com.cakin.forms.UserForm;
public class LoginAction extends Action {
private int num=0;
//我们需要重新编写一个方法:execute会被自动调用,有点类似servlet的service方法。
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//把form转成对应的UserForm对象
UserForm userForm=(UserForm)form;
num++;
//简单验证
if("123".equals(userForm.getPassword())){
//把名字存放到request对象域
//request.setAttribute("username", userForm.getUsername());
request.setAttribute("num",num+"");
return mapping.findForward("ok");
}
else{
return mapping.findForward("err");
}
}
}
2 wel.jsp
<%@ page language="java" import="java.util.*" import="com.cakin.forms.*" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'wel.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">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
welcome <%=((UserForm)session.getAttribute("userForm")).getUsername() %> <br>
<a href="/strutslogin/">返回重新登录</a>
num=<%=request.getAttribute("num") %>
</body>
</html>
三 测试结果
阅读全文
0 0
- struts中的action是单态的
- struts action-mapping中的input的作用
- Struts中的Action方法
- Struts中的action
- struts中的action类
- struts中的默认action,当请求的action不存在的时候,被默认action接收
- struts中action中的种类
- struts中的各种action类
- struts中action中的函数
- struts.xml配置文件中的action的各项默认值
- 总结一:jsp调用struts的action类中的map
- Struts的action理解
- Struts的Action类
- Struts常用的Action
- Struts 2 的Action
- struts 的 Action
- 关于Struts的Action
- Struts里面的Action
- Struts小项目二
- struts-config文件路径问题
- golang 构建数据服务
- React Native 学习(二)---仿微信我的钱包界面
- Call requires API level 16 (current min is 15):
- struts中的action是单态的
- struts框架访问数据库
- 使用工具半自动化开发struts
- 递推式的矩阵优化
- 全自动化开发struts
- Struts基本介绍
- jstl最常用的标签之<c:out>
- jstl最常用的标签之<c:set>
- CPU之分支跳转优化