想写一个简单的页面来测试接口,但我又不想麻烦的去配springmvc,就用了比较老的servlet
在web.xml是这样配置的
<servlet> <description></description> <display-name>newDataQuery</display-name> <servlet-name>newDataQuery</servlet-name> <servlet-class>com.new.newDataQuery</servlet-class> </servlet> <servlet-mapping> <servlet-name>newDataQuery</servlet-name> <url-pattern>/newDataQuery</url-pattern> </servlet-mapping>
applicationContext-dao.xml下dao的配置
<bean id="newResultDao" class="com.new.impl.NewResultImpl"> <property name="dataSource"> <ref bean="dynamicJdbc" /> </property> </bean>
在action下可以这样访问dao
private NewResultDao cr; public NewResultDao getCr() { return cr; } public void setCr(NewResultDao cr) { public void init(ServletConfig config) throws ServletException { super.init(config); ServletContext servletContext = this.getServletContext(); WebApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(servletContext); cr = (NewResultDao)ctx.getBean("newResultDao"); }