1 Configuring Spring Files
<bean id= "Hibernatetemplate" class= "Org.springframework.orm.hibernate3.HibernateTemplate" >
<property name= "Sessionfactory" ref= "Sessionfactory" ></property>
</bean>
<bean id= "JdbcTemplate" class= "Org.springframework.jdbc.core.JdbcTemplate" >
<property name= "DataSource" ref= "DataSource"/>
</bean>
2 load Spring's configuration file in Web.xml
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
Classpath*:/spring/applicationcontext_*.xml
</param-value>
</context-param>
3 Gets the bean whose name is Jdbctemplat in the servlet.
public class Userauthorizationfilter extends HttpServlet {
Private Webapplicationcontext WAC;
public void init () {
Method One: WAC =webapplicationcontextutils.getrequiredwebapplicationcontext (
This.getservletcontext ());
Method Two: WAC = Webapplicationcontextutils.getwebapplicationcontext (
This.getservletcontext ());
Method One and method two get the same result.
Type of WAC: Org.springframework.web.context.support.XmlWebApplicationContext
}
public void DoPost (HttpServletRequest request, httpservletresponse response)
Throws Servletexception, IOException {
JdbcTemplate JdbcTemplate = (jdbctemplate) wac.getbean ("JdbcTemplate");
String sql= "SELECT COUNT (*) from the customer where name= ' liwj ' and password= ' 1111111 '";
int num=jdbctemplate.queryforint (SQL);
if (num==1) {