如何在Spring中注入servlet配置组件?
来源:互联网 发布:济南网络广播电视台app 编辑:程序博客网 时间:2024/05/16 15:30
在servlet中可用此取得publicservice业务服务对象:
public class RetrievedataproxyBean extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
PrintWriter out = res.getWriter();
WebApplicationContext ctx=WebApplicationContextUtils.getRequiredWebApplicationContext(this.getServletContext());
PublicService publicservice=(PublicService)ctx.getBean("publicservice");
String datatype = (String) req.getParameter("dt");
// 根据请求的参数,来决定返回数据内容 --需要请求的是抽奖模块
if (datatype.equalsIgnoreCase("drawmeasures")) {
String start = (String) req.getParameter("start");
String limit = (String) req.getParameter("limit");
try {
int index = Integer.parseInt(start);
int pageSize = Integer.parseInt(limit);
System.out.println("run here");
//
List<Drawmeasureindex> lst=new ArrayList<Drawmeasureindex>();
lst=publicservice.getAllDrawmeasure(); //完成业务需求
int j=1;
String json = "{totalProperty:100,root:[";
System.out.println(json);
for(Iterator itr=lst.iterator();itr.hasNext();)
{
Drawmeasureindex objtmp=(Drawmeasureindex)itr.next();
json += "{id:" + j + ",name:'" + objtmp.getDrawmeasurename() + "',descn:'" +objtmp.getDrawmeasurename() + "'},";
}
json=json.substring(0, json.length()-1);//去除最后一个分号
json += "]}";
/*for (int i = index; i < pageSize + index; i++) {
json += "{id:" + i + ",name:'name" + i + "',descn:'descn" + i + "'}";
if (i != pageSize + index - 1) {
json += ",";
}
}
json += "]}";*/
System.out.println(json);
out.write(json);
} catch (Exception ex) {
} }
}
}
在web.xml中:
<servlet>
<servlet-name>retrievedataproxyservlet</servlet-name>
<servlet-class>com.gisco.adsys.view.bean.RetrievedataproxyBean</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>retrievedataproxyservlet</servlet-name>
<url-pattern>/servlet/retrievedata</url-pattern>
</servlet-mapping>
本文转载自:http://www.cnblogs.com/orchidsure/archive/2009/05/18/1459702.html
- 如何在Spring中注入servlet配置组件?
- servlet中如何调用spring中注入的对象
- 如何让servelt和Filter注入到spring容器或者在servlet中调用spring中的bean
- 在servlet中注入spring容器中的bean
- 在servlet中注入spring容器中的bean
- SpringMVC项目中偶尔用到servlet,如何在servlet中注入service笔记
- 在servlet中用spring @Autowire 注入.
- 如何在spring框架中给接口属性注入??
- 如何在非注入类中,获取spring容器
- 使用spring向servlet中注入
- Servlet中注入Spring的bean
- Spring向Servlet中注入实例
- Servlet中使用Spring注入Service层
- 使用spring向servlet中注入
- Spring+Servlet整合(如何向Servlet注入属性)
- 在servlet中如何使用被Spring管理的service
- 在Spring中注入配置文件
- 在spring中如何配置的log4j
- 转发:一个总经理的11个经典面试问题
- 博客迁移说明
- Try
- 网站制作二 : 细节做起,不要看不起网站制作人员,其实技术含量蛮高的!
- 回车键触发表单提交的问题
- 如何在Spring中注入servlet配置组件?
- JSP中出现According to TLD or attribute directive in tag file
- 用SQL建立索引
- JavaScript加密解密
- json初学习
- sql索引类型
- JSP几种跳转方式
- VGA采集卡
- Socket编程:由Linux向Windows移植问题