java中request,application,session三个域及参数简单示例

直接上代码:

java代码:

public class HelloAction implements Action {
    @Override
    public String execute() throws Exception {
        Map<String, Object> requestScope = (Map<String, Object>) ActionContext.getContext().get("request");
        Map<String, Object> sessionScope = ActionContext.getContext().getSession();
        Map<String, Object> applicationScope = ActionContext.getContext().getApplication();
        Map<String, Object> params = ActionContext.getContext().getParameters();
        requestScope.put("name", "request");
        sessionScope.put("name", "session");
        applicationScope.put("name", "application");
        String[] strs = (String[]) params.get("name");
        System.out.println(Arrays.toString(strs));
        return SUCCESS;
    }
}

jsp页面

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${requestScope.name}<br/>
${sessionScope.name}<br/>
${applicationScope.name}<br/>
</body>
</html>

访问的时候追加name参数,后台就会打印参数值

posted @ 2015-07-22 19:24  jiapeng  阅读(577)  评论(0编辑  收藏  举报