导入JSONObject时出错

时间:2015-10-20 09:31:50

标签: java json eclipse servlets eclipse-indigo

我正在使用JSONObject但是当我导入import org.json.simple.JSONObject;时,它会显示编译错误,如下所示:

  

即无法解析类型java.util.Map$Entry。它是从必需的.class文件中间接引用的。

请帮我解决这个问题。

package Servlet;
import java.io.FileReader; 
import java.io.IOException; 
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.json.simple.JSONObject; 
import org.json.simple.parser.JSONParser;
/**
  * Servlet implementation class LoginServlet
 */
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public LoginServlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
}

/**
 *    @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
 */
      protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
     response.setContentType("text/html");  
        PrintWriter out=response.getWriter();  

        request.getRequestDispatcher("link.html").include(request, response);  

        String name=request.getParameter("name");  
        String password=request.getParameter("password");  

        JSONParser parser=new JSONParser();
        Object obj=parser.parse(new FileReader("/home/mukesh/Downloads/Downloads/Json Files/mukesh.json"));
        JSONObject ob=(JSONObject)obj;
        if(ob.get(name)==password){
            out.print("You are successfully logged in!");  
            out.print("<br>Welcome, "+name);  

            Cookie ck=new Cookie("name",name);  
            response.addCookie(ck);  
        }else{  
            out.print("sorry, username or password error!");  
            request.getRequestDispatcher("login.html").include(request, response);  
        }  

        out.close(); 
    }

}

1 个答案:

答案 0 :(得分:0)

鉴于eclipse-indigo标签以及我无法发表评论以询问有关eclipse版本和JDK的更多信息的事实,我猜你应该关注这个question

特别是这个答案:

  

通过将我的Eclipse IDE版本从indigo更改为luna来解决这个问题。 Luna支持Java 8,因此所有问题现已得到解决。