新地球 2017-08-04 08:33 采纳率: 0%
浏览 1457

java Servlet中转换成json运行报错了,求助

错误: 代理抛出异常错误: java.rmi.server.ExportException: Port already in use: 1099; nested exception is:
java.net.BindException: Address already in use (Bind failed)
具体代码如下:

@Override
protected  void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException,IOException {
    response.setCharacterEncoding("UTF-8");
    response.setContentType("application/json; charset=utf-8");
    String jsonStr= null;
    try {
        jsonStr = this.jsonString();
    } catch (JSONException e) {
        e.printStackTrace();
    }

    //array.toString()
    PrintWriter out = null;
    try {
        out = response.getWriter();
        out.write(jsonStr);
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

String jsonString() throws JSONException{
JSONObject json = null;
json = new JSONObject();
json.put("username", "wanglihong");
json.put("height", "12.5");
json.put("age", 24);

 String jsonStr= json.toString();
 return jsonStr;

}

  • 写回答

3条回答 默认 最新

  • Tsui丶 2017-08-04 08:36
    关注

    你的1099端口被占用了,然后现在你需要使用1099端口所以就报错了
    处理方法:
    https://jingyan.baidu.com/article/215817f784c2d61eda1423c4.html

    评论

报告相同问题?