当前位置: 代码迷 >> J2EE >> springMvc定义接口本地测试有关问题
  详细解决方案

springMvc定义接口本地测试有关问题

热度:107   发布时间:2016-04-17 23:03:41.0
springMvc定义接口本地测试问题。
最近让我开发一个接口供其它系统调用查询,以前没做过,想本地测试一下看看如何返回json串,但是本地测试不了,一直报Java.lang.io.fileNotFoundException,我写的访问地址访问不了(http://127.0.0.1:8080/SpringMvc_test/getCollection.do)。
求教测试的问题。
@Controller
@Transactional
@RequestMapping("/cjServer")
public class CjHttpRequestInter {
/**
 * 催记查询接口
 */
@RequestMapping(value="/getCollection",method={RequestMethod.POST})
@ResponseBody
public Map<String,String> queryCjServer(HttpServletRequest request){
String productId = request.getParameter("productId");
String endTime = request.getParameter("endTime");
System.out.println("productId:"+productId+",endTime:"+endTime);
Map<String,String> result = new HashMap<String,String>();
result.put("returnCode", "0");
result.put("message", "测试数据");
return result;
}
}

public class HttpRequestTest {
public static void main(String[] args) throws IOException {
HttpRequestUtil httpUtil = new HttpRequestUtil();
String url = "http://127.0.0.1:8080/SpringMvc_test/cjServer/getCollection.do";
StringBuffer param = new StringBuffer();
param.append("custNo=465827476879183872");
JSONObject jsonResult = httpUtil.httpRequestMethod(url, param.toString());
try {
System.out.println("returnCode:"+jsonResult.getString("returnCode")+",returnMessage:"+jsonResult.getString("returnMessage"));
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

报错是在这里
// 定义BufferedReader输入流来读取URL的响应
in = new BufferedReader(new InputStreamReader(
conn.getInputStream(), "UTF-8"));

------解决思路----------------------
http://127.0.0.1:8080/SpringMvc_test/cjServer/getCollection.do
你把这个地址放到浏览器打开
------解决思路----------------------
引用:
http://127.0.0.1:8080/SpringMvc_test/cjServer/getCollection.do
你把这个地址放到浏览器打开


对头,用浏览器打开,如果能看到json数据那就说明是你代码的问题,与spring mvc没关系
------解决思路----------------------
http://127.0.0.1:8080/SpringMvc_test/cjServer/getCollection.do
按理说 类上的路径加上方法上的路径是不会错的。
还是404 的话  看下你的端口是不是正确的,看看你的工程名是不是SpringMvc_test

------解决思路----------------------
因为你设置的getCollection方法是post方法,把post放开再看
 @RequestMapping(value="/getCollection") 
  相关解决方案