定义
ActionContext.getContext().getSession().put("tt","猪猪");
获取<body> ${sessionScope.tt}为什么直接输出${sessionScope.tt} 而没有取出tt的值呢?
ActionContext.getContext().getSession().put("tt","猪猪");
获取<body> ${sessionScope.tt}为什么直接输出${sessionScope.tt} 而没有取出tt的值呢?
解决方案 »
- java工程师的困惑~散分
- 怎么改掉粗心的毛病
- 集成 spring + hibernate + struts 数据库映射问题 找不到数据库表
- java转换xslt问题!急!!!!!!!!!!!!!!!
- Hibernate 里 的session.delete()删除对象时候,出错?
- 成功在JBOSS4.2中发布项目,但进项目主页时却发生异常
- Java多线程如何得知一个线程是正在sleep或是wait?
- 想在jsp页面中实现下载功能 文件路径为(c:/jboss/bin/aaa.jar);请问如何用超链接实现
- 500分请教struts问题
- java,IBM websphere MQ问题求教
- struts2怎么判断session中某个属性为null?
- ssh 整合的功能比较完善的论坛 或者 网站
<%@ page isELIgnored ="false"%>
我这里有个最简单的例子:
action:LoginAction.java
package liu_ss;import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;//struts2的Action继承ActionSupport
public class LoginAction extends ActionSupport {
// 定义封装请求参数的username和password的属性
private String username;
private String password;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
//定义用户请求的execute方法
public String execute() throws Exception {
if(getUsername().equals("liu") && getPassword().equals("liu")){
ActionContext.getContext().getSession().put("user", getUsername());
return SUCCESS;
}else{
return ERROR;
}
}
}welcome.jsp<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><s:text name="succPage"></s:text></title>
</head>
<body>
${sessionScope.user }
</body>
</html>
<%@taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title><s:text name="succPage"></s:text></title>
</head>
<body>
${sessionScope.user }
</body>
</html>