火狐 --POST请求

第一种状况java

webservice端代码web

@Path("/DoSearch")
public class DoSearchWebService {
    @Context UriInfo uriInfo;
    @Context Request request;
    @Context HttpServletRequest re;
    
    @POST
    @Produces( { MediaType.APPLICATION_JSON })
    public BooksList getBooksList(
            @FormParam("SearchKey") String searchKey,
            @FormParam("UserId") String userId,
            @FormParam("PageNo") String pageNo,
            @FormParam("Count") String pageCount) {
        List<BooksListData> listData = new ArrayList<BooksListData>();
     
        String resultCode = "0"; 
        String resultMsg = "";
        String resultCount = "0";
         
        BooksList booksList = new BooksList();
        try {
             
            listData =DaoFactory.getMeetingTypeDaoImp().getBooksListByKey(searchKey,userId, pageNo, pageCount);
            resultCount=listData.size()+"";
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }

用火狐浏览器模拟POST请求时,设置以下json

headers里面的设置以下:浏览器


header里面的设置要和这里对应app

@Produces( { MediaType.APPLICATION_JSON })

备注:第一种状况是,参数一块儿传入(可是分红单个),单个解析。
code


第二种状况orm

webservice代码对象

@Controller
@RequestMapping("/DoSearch")

public class AddCustomerInfoController {
    
    @Autowired
    private GetCustomerVagueInfoMapper getCustomerVagueInfoMapper;
    
    @SuppressWarnings("unchecked")
    @RequestMapping(method = RequestMethod.POST)
    public @ResponseBody
    Object getUpdateInfo(@RequestBody String addInfo,
            HttpServletRequest request,HttpServletResponse response)throws Exception
    {
        //1.接收添加信息
        JSONObject getObject = JSONObject.fromObject(addInfo);

        //返回对象
        JSONObject data = new JSONObject();
        BasicsBean<JSONObject> returnBean = new BasicsBean<JSONObject>();
        
        //传参
        HashMap<String, Object> map = new HashMap<String, Object>();
        map.put("SearchKey", getObject.get("SearchKey"));
        map.put("UserId", getObject.get("UserId"));
        map.put("PageNo", getObject.get("PageNo"));
        map.put("Count", getObject.get("Count"));
        
        return returnBean;
   }

用火狐浏览器模拟POST请求时,设置以下字符串

备注:第二种状况,参数总体传输,做为一个字符串,这种形式是将body里面的内容当成一个json对象传输,webservice这端用addInfo这个对象(字符串对象,它能够转成json格式的对象)来接收,而后转成json格式对象来解析。get

相关文章
相关标签/搜索