? hello, there. I am a student from Taiwan.
Recently I am studying JavaSpring, and I start with HelloWorld sample.
my problem is:
In index.jsp, this statement
WebApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(application);
I think it is used to register(or connect?) the ContextLoader in web.xml so that I could use it to get beans. But I would like to know that why I could only send "application" as a variable even I couldn't find any declaration of this variable in my program. How did that work without undefined error?
Even I entered the class it imported above, still has no found about this.
Here is the code that sample offer me that I should add to index.jsp file:
<%@page import="org.springframework.web.context.WebApplicationContext"%>
<%@page import="org.springframework.web.context.support.WebApplicationContextUtils"%>
<%
WebApplicationContext context = WebApplicationContextUtils
.getWebApplicationContext(application);
%>
and my web.xml:
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/ctx_ut.xml</param-value>
</context-param>
<filter>
<filter-name>requestContextFilter</filter-name>
<filter-class>org.springframework.web.filter.RequestContextFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>requestContextFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<servlet>
<servlet-name>context</servlet-name>
<servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
</web-app>
my bean setting ctx_ut.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>WEB-INF/hello.properties</value>
</property>
</bean>
<bean id="dataSource" class="spring01.HelloWorld" scope="request">
<property name="message" value="${hi}"></property>
</bean>
<bean id="seeyou" class="spring01.SeeYou" scope="request">
<constructor-arg value="${seeYou}" />
<constructor-arg ref="dataSource" />
</bean>
<bean id="goodbye" class="spring01.Goodbye" depends-on="seeyou"
init-method="init" scope="request">
<property name="helloWorld" ref="dataSource"></property>
<property name="message" value="${goodbye}"></property>
</bean>
</beans>
(I guess class file is not important here so I didn't put here, it's just some string setter and getter.)
Is there any concept I misunderstand or any document had described it? please tell me and share the link.
First ask, hope my problem is clear enough. Thanks.