標籤:
在jsp中出現
提取的代碼:
<%
WebApplicationContext wac = WebApplicationContextUtils
.getWebApplicationContext(this.getServletContext());
UserDao userDao = (UserDao) wac.getBean("userDaoImpl");
String in=(String)request.getParameter("id");
System.out.println(in);
int num=Integer.parseInt(in);
%>
<%=userDao.findUserById(num)%><br />
WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
WebApplicationContext 是什嗎?
WebApplicationContextUtils是什嗎?
this.getServletContext()又是什嗎?
這句話的意思是,通過WebApplicationContextUtils工具類擷取ApplicationContext對象.這個對象是通過.getServletContext()方式擷取的,然後把擷取的ApplicationContext對象賦值給wac。
WebApplicationContext是spring包中的一個類
WebApplicationContextUtils是Spring 包中的一個工具類
getServletContext()是struts2中擷取參數的方法
WebApplicationContext wac=WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());這句話的意思