概述
start.jsp :
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<form action="sample" method="post">
username:<input type="text" name="username"><br>
<input type="submit" value="confirm">
</form>
</body>
</html>
struts.xml :
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="demo" extends="struts-default">
<action name="sample" class="action.SampleAction">
<result name="success">/showInfo.jsp</result>
</action>
</package>
</struts>
SampleAction.java :
public class SampleAction {
private String username;
private String msg;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
public String execute(){
System.out.println("username:"+username);
msg="Action Value Message";
Map<String,Object> request=
(Map<String,Object>)ActionContext.getContext().get("request");
request.put("msg","Request Value Message");
Map<String,Object> session=ActionContext.getContext().getSession();
session.put("msg","Session Value Message");
Map<String,Object> application=ActionContext.getContext().getApplication();
application.put("msg","Application Value Message");
return "success";
}
}
showInfo.jsp :
<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>Insert title here</title>
</head>
<body>
<b>action message</b>:<s:property value="msg"/><br>
<b>request message</b>:<s:property value="#request.msg"/><br>
<b>session message</b>:<s:property value="#session.msg"/><br>
<b>application message</b>:<s:property value="#application.msg"/><br>
<b>attr message</b>:<s:property value="#attr.msg"/><br>
<b>action parameters</b>:<s:property value="username"/><br>
<b>context parameters</b>:<s:property value="#parameters.username"/><br>
<s:debug></s:debug>
</body>
</html>
最后
以上就是成就舞蹈为你收集整理的Struts2标签库(3):利用
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复