码迷,mamicode.com
首页 > 其他好文 > 详细

NC中配置Servlet 调用NC服务

时间:2015-10-22 21:07:20      阅读:1686      评论:0      收藏:0      [点我收藏+]

标签:

1.新建Servlet类(这个类中有实现调用接口的方法以及设置Token)路径没有要求,应该新建Servlet本来就不是规范。

package nc.impl.ca.cuma.account.ma;
 
import java.io.BufferedReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;
 
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
import nc.bs.ca.capub.service.NCLocatorFactory;
import nc.bs.framework.common.NCLocator;
import nc.bs.framework.comn.NetStreamContext;
import nc.bs.framework.core.service.IFwLogin;
import nc.jdbc.framework.processor.MapListProcessor;
import nc.pubitf.ca.cuma.account.ma.IMACoverPlanService;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
 
public class CoverPlanServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
private MapListProcessor myMapListprocessor;
 
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
response.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
JSONObject paraJson = JSONObject.fromObject(request
.getParameter("data"));
String userId = paraJson.getString("userId");
String groupId = paraJson.getString("groupId");
PrintWriter out = response.getWriter();
IFwLogin login =(IFwLogin)NCLocatorFactory
.getInstance().getCANCLocator().lookup("nc.bs.framework.core.service.IFwLogin");
NetStreamContext.setToken(login.login("yg","111aaa",null));
IMACoverPlanService PlanService = (IMACoverPlanService) NCLocatorFactory
.getInstance().getCANCLocator()
.lookup("nc.pubitf.ca.cuma.account.ma.IMACoverPlanService");
List<Map> coverPlanList=PlanService.getCoverPlanList(groupId,userId, null, null, "0", "10");
String returnJson = JSONArray.fromObject(coverPlanList).toString();
out.write(returnJson);
 
out.flush();
out.close();
}
 
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
this.doGet(request, response);
}
 
// public String readJSONString(HttpServletRequest request) {
// StringBuffer json = new StringBuffer();
// String line = null;
// try {
// BufferedReader reader = request.getReader();
// while ((line = reader.readLine()) != null) {
// json.append(line);
// }
// } catch (Exception e) {
// System.out.println(e.toString());
// }
// return json.toString();
// }
 
}
2.在account.portal.part中配置Servlet(注意使用一下LFW工具--->同步所有元素--->重启NC服务
<?xml version="1.0" encoding="UTF-8" ?>
<web-app>
<context-param>
<param-name>ctxPath</param-name>
<param-value>/account</param-value>
</context-param>
 
<context-param>
<param-name>modules</param-name>
<param-value>account</param-value>
</context-param>
<servlet>
<servlet-name>CoverPlanServlet</servlet-name>
<servlet-class>nc.impl.ca.cuma.account.ma.CoverPlanServlet2</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CoverPlanServlet</servlet-name>
<url-pattern>/CoverPlanServlet</url-pattern>
</servlet-mapping>
 
</web-app>
3.通过网页请求访问
 
http://IP:port/portal/CoverPlanServlet
4.简单的结果演示(CoverPlanServlet2只是我方便说明问题,不是上面的CoverPlanServlet)
技术分享
5.第三方网页通过ajax请求如下(但是ajax会存在跨域问题,慎用,一般可以把第三方网页挂在NC工程中,这样就不存在跨域的问题了)
var json={"edit":[{"bh":"11111","mc":"11111","dbms":"ORACLE9i","dwmmc":"","addr":"","username":"","password":"","rm_sz":"ck","nyr_sz":"","id":"-1"},{"bh":"121","mc":"12","dbms":"ORACLE9i","dwmmc":"12","addr":"12","username":"12","password":"12","rm_sz":"ck","nyr_sz":"2011-09-06","id":"13"}],"del":["12"]};
var post={data:JSON.stringify(json)};//JSON.stringify(json)把json转化成字符串
//$.post(url,post);
 
$(document).ready(function(){
alert("ready in...");
//$("#send").click(function(){
alert("#send in...");
$.post("/portal/CoverPlanServlet",
post,
function(data,textStatus){
alert("数据:" + data + "\n状态:" + textStatus);
});
// });
});
6.第三方网页存放的位置
技术分享技术分享
 

NC中配置Servlet 调用NC服务

标签:

原文地址:http://www.cnblogs.com/lanzhiming/p/4902429.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!