java常用的交互信息获取

1.获取request对象

//方式一
HttpServletRequest request = (HttpServletRequest) ActionContext  
			.getContext().get(ServletActionContext.HTTP_REQUEST); 
//方式二
HttpServletRequest request = ServletActionContext.getRequest(); 

2.获取response对象

HttpServletResponse response = ServletActionContext.getResponse();


3.获取session对象

HttpSession session =ServletActionContext.getRequest().getSession(); 

4.读取applicationContext.properties中变量的值

String dbType = PropertiesBean.getInstance().getProperty("conf.rightdata.type"); 

5.java对字符串转码

String charset = new String(str.getBytes("ISO8859-1"), "UTF-8"); 

6.通过java.util.UUID获取uuid

public static String getUUId() {  
	UUID uuid = UUID.randomUUID();  
	String uid = uuid.toString().replace("-", "");  
	return uid;  
} 

7.通过StringUtils判断字符串不为""或null

boolean isEmpty = StringUtils.isNullOrEmpty(str); 

8.读取bean对象

ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml"); 
UserDao userDao = (UserDao)context.getBean("userDao");


你可能感兴趣的:(request,session,response)