标签:
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();
// }
}
<?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>
http://IP:port/portal/CoverPlanServlet
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);
});
// });
});
标签:
原文地址:http://www.cnblogs.com/lanzhiming/p/4902429.html