我使用JSONObject
但是當我導入import org.json.simple.JSONObject;
話,就說明編譯錯誤如下:錯誤而進口的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();
}
}
我猜你正在使用JDK 1.8?你也使用Eclipse,如果是的話,是什麼版本? –
我正在使用eclipse indigo。 –
我在將「obj」即我的對象轉換爲JSONObject時遇到此錯誤,因此應該如何解決此問題,而不是從eclipse-indigo更改爲eclipse-luna。 –