NC中配置Servlet 调用NC服务

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.第三方网页存放的位置

时间: 2024-10-16 13:45:12

NC中配置Servlet 调用NC服务的相关文章

springmvc中配置servlet初始化类

<bean  id="InitStart" lazy-init="false" init-method="InitSystem" class="my.spring.uitl.InitStart"></bean> 配置在springmvc的配置文件中 只要项目启动,就会默认执行这个类的这个方法 相比静态类代码块的好处, 有点在tomcat启动时就会调用如果有错立即报错,静态代码块,调用时才会报错 作用 可

如何在.xml中配置Servlet信息

在编写好servlet文件后需要在web.xml文件下配置servlet,才能使servlet在服务器上运行.基本配置方式如下所示 <servlet> <servlet-name>helloServlet</servlet-name> <servlet-class>com.hamigua.servlet.HelloServlet</servlet-class> <load-on-startup>1</load-on-startu

spring中配置quartz调用两次及项目日志log4j不能每天生成日志解决方法

在quartz中配置了一个方法运行时会连续调用两次,是因为加载两次,只需在tomcat的server.xml中修改配置 <Host name="www.xx.cn" appBase="" unpackWARs="true" autoDeploy="true"> <Context path="" docBase="webapps/demo" reloadable=&quo

servlet3.0以后无需在web.xml中配置servlet

//下面这句话代替了web.xml中对servlet的配置 @WebServlet("/Upload") public class Upload extends HttpServlet { private static final long serialVersionUID = 1L; protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletExceptio

在 vSphere 5.x/6.0 中配置 Network Dump Collector 服务 (2002954)

vmware KB: https://kb.vmware.com/s/article/2002954?lang=zh_CN 重点配置命令: 使用 vSphere Client 连接到 vCenter Server 系统 编辑主机配置文件如下两项时,在合规性检查时总是提示通不过 1. Syslog 2. ESXi Dump Collector 但是通过ESXCLI 配置 ESXi Dump Collector和Syslog 就没问题 ESXi Dump Collector配置命令: esxcli

使用框架时,在web.xml中配置servlet时,拦截请求/和/*的区别。

关于servlet的拦截设置,之前看了好多,说的都不太清除,明白. 最近明白了一些,总的来说就是保证拦截所有用户请求的同时,放行静态资源. 现整理如下: 一.我们都知道在基于Spring的Application中,需要在web.xml中增加下面类似的配置信息: 1 <listener> 2 <listener-class> 3 org.springframework.web.context.ContextLoaderListener 4 </listener-class>

Selenium中配置链接使用FTP服务

Enable the default report solution Step1: Create a suite listener and add codes into it, please watch the blue box more carefully. Step2: Enable the new listener in the TestNG configuration file Step3: add ftp settings and the recipient of email in t

Java+MyEclipse+Tomcat (二)配置Servlet及简单实现表单提交

在Java EE应用编程中Servlet是基础,JSP是建立在Servlet基础之上的,其他Web框架如Struts.WebWork和Spring MVC都是基于Servlet的.本文主要讲述MyEclipse和Tomcat配置Servlet的过程和简单实现表单提交功能. 希望对大家有所帮助,参考书籍<Java EE企业级应用开发实例教程>. Java+MyEclipse+Tomcat (一)配置过程及jsp网站开发入门 一. Servlet编程 1.Web基础知识 在讲述Servlet之前,

ckeditor编辑器在java项目中配置

一.基本使用: 1.所需文件架包 A. Ckeditor基本文件包,比如:ckeditor_3.6.2.zip 下载地址:http://ckeditor.com/download 2.配置使用 A.将下载下来的CKEditor压缩解压,将解压后的文件夹("ckeditor")拷贝进项目里面,比如我是放在"WebContent"的"commons"文件夹下: B.在需要使用CKEditor的页面引入CKEditor的支持javascript <