an action feature
Actions are monomorphic, including ActionServlet.
Monomorphism means: in the whole process of running the program, it is always an object.
Two Action Monomorphic Characteristic Proof
1
LoginAction
package com.cakin.actions;
//This is an action (representing the team leader, which needs to inherit 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;
//We need to rewrite a method: execute will be called automatically, somewhat similar to the service method of servlet.
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// Convert the form to the corresponding UserForm object
UserForm userForm=(UserForm)form;
num++;
// simple verification
if("123".equals(userForm.getPassword())){
//Store the name in the request object field
//request.setAttribute("username", userForm.getUsername());
request.setAttribute("num",num+"");
return mapping.findForward("ok");
}
else{
return mapping.findForward("err");
}
}
}
2
yes.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
>
三 测试结果