httpClient发送post请求到springmvc,接收请求后,无法再内部跳转
因项目需要,发送http请求方式为post,json数据放在body里。但现在问题是http请求在springmvc里controller已经能接收到,json数据也可以解析出来。但是我需要接收完请求后,根据不同的品牌进行不同的controller处理,所以是需要接收完请求后就要跳转到,例如:redirect:./picc/ppartinfo.do 。现在我做了一个测试,当我是用一个jsp的form表单发送的post请求,到了接收请求的controller,是可以再去内部跳转,例如:redirect:./picc/ppartinfo.do ;但是我是使用http发送的post请求,也可以到接收请求的controller,但到了跳转redirect:./picc/ppartinfo.do 就没有反应了,也没有报错。想问一下这个是什么问题?
1、post方式发送的http请求测试类。
//对接口进行测试
public class TestMain {
private String url = "http://localhost:8080/ComplexDemander/piccpart.do";
private String charset = "utf-8";
private HttpClientUtil httpClientUtil = null;
public TestMain(){
httpClientUtil = new HttpClientUtil();
}
public void test(){
String httpOrgCreateTest = url;
Map<String,String> createMap = new HashMap<String,String>();
Map<String,String> createMap3 = new HashMap<String,String>();
List<Map> l=new ArrayList<Map>();
createMap.put("TransactionCode","01");
createMap.put("Filter","NO");
createMap.put("VinCode","X4XKS494500H03020");
createMap3.put("PartName","前保");
l.add(createMap3);
createMap3.put("PartName","前保险杠骨架");
l.add(createMap3);
createMap3.put("PartName","前保险杠支架(左)");
l.add(createMap3);
createMap.put("PartsList", l.toString());
String httpOrgCreateTestRtn = httpClientUtil.doPost(httpOrgCreateTest,createMap,charset);
System.out.println("result:"+httpOrgCreateTestRtn);
}
public static void main(String[] args){
TestMain main = new TestMain();
main.test();
}
}
2、接收请求的controller
@Controller
@RequestMapping("/")
public class PFocusController {
/**
* 获取vin与json数据包,根据vin与配件条件查询出数据
*/
@RequestMapping(value="piccpart.do",method=RequestMethod.POST,produces={"application/json;charset=UTF-8"})
public String getPartByName(HttpServletRequest request, HttpServletResponse response)
{
try {
BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(),Charset.forName("UTF-8")));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = in.readLine()) != null) {
sb.append(line);
}
String jstr=sb.toString();
//中文解码
jstr = URLDecoder.decode(URLDecoder.decode(jstr,"utf-8"),"utf-8");
request.getSession().setAttribute("jstr", jstr);
// String jstr=tes.getJSon(); //获取的文本json数据 内部测试
// request.getSession().setAttribute("jstr", jstr.toString());
// return new ModelAndView("redirect:/toList");
return "redirect:./picc/ppartinfo.do";
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
3、需要内部跳转的controller的部分代码
@RequestMapping(value="ppartinfo.do",produces={"application/json;charset=UTF-8"})
@ResponseBody
public String getPPart(String vin,HttpServletRequest request,HttpServletResponse response)
{
System.out.println("进入处理Controller");
return "";
}
请各位大哥帮忙看看,解决一下。好急!