当前位置: 首页 > 知识库问答 >
问题:

POST http://localhost:8080/server2_0_war_explorded/user返回的响应状态为500内部服务器错误

赏航
2023-03-14

客户端控制器中的createUser()

public void createUser() {
    JsonObject data = new JsonObject();

    Scanner input = new Scanner(System.in);

    System.out.println("Input your firstname");
    data.addProperty("firstname", input.nextLine());

    System.out.println("Input your Lastname");
    data.addProperty("lastname", input.nextLine());

    System.out.println("Input your Email");
    data.addProperty("email", input.nextLine());

    System.out.println("Input your Username");
    data.addProperty("username", input.nextLine());

    System.out.println("Input your Password");
    data.addProperty("password", input.nextLine());

    data.addProperty("usertype", "0");

    Connection.postUser(data);


}

客户端连接类中的PostUser()

public static String postUser(JsonObject data) {
    ClientResponse clientResponse = HttpRequests.post("/user/", Crypter.encryptDecryptXOR(new Gson().toJson(data)));

    String response = null;

    if (clientResponse == null) {

        System.out.println("Error on SDK");
    } else {
        response = clientResponse.getEntity(String.class);
        if (clientResponse.getStatus() == 200) {
            System.out.println(response);
        } else
            System.out.println("error");
    }
    clientResponse.close();
    return response;

}

客户端HttpRequests类中的Post方法

public static ClientResponse post(String path, String data) {
    ClientResponse clientResponse = null;

    try {

        WebResource webResource = client
                .resource("http://localhost:8080/server2_0_war_exploded")
                .path(path);

        clientResponse = webResource.accept("application/json").post(ClientResponse.class, data);
    }
    catch
            (UniformInterfaceException | ClientHandlerException e) {
        e.printStackTrace();
    }
    return clientResponse;
}
@POST
@Produces("application/json")


public Response create(String data) throws Exception {
    String s = new Gson().fromJson(data,String.class);
    String decrypt = Crypter.encryptDecryptXOR(s);
    if (controller.addUser(decrypt)) {
        return Response
                .status(200)
                .entity("{\"message\":\"Success! User added\"}")
                .build();

    }
    else return Response.status(400).entity("{\"message\":\"failed\"}").build();
}
public boolean addUser(User u) throws Exception {

    PreparedStatement addUserStatement =
            conn.prepareStatement("INSERT INTO Users (First_Name, Last_Name, Username, Email, Password, Usertype) VALUES (?, ?, ?, ?, ?, ?)");

    try {
        addUserStatement.setString(1, u.getFirstName());
        addUserStatement.setString(2, u.getLastName());
        addUserStatement.setString(3, u.getUsername());
        addUserStatement.setString(4, u.getEmail());
        addUserStatement.setString(5, u.getPassword());
        addUserStatement.setBoolean(6, u.getUserType());

        addUserStatement.execute();
    } catch (SQLException e) {
        e.printStackTrace();
    }
    return true;
}

创建用户

2

输入你的名字

输入您的用户名

朋友

输入密码

        if (clientResponse.getStatus() == 200) { clientResponse: "POST http://localhost:8080/server2_0_war_exploded/user returned a response status of 500 Internal Server Error"

共有1个答案

裴欣荣
2023-03-14

您的当前代码:

客户端(生成json文本、加密并发送):

    ClientResponse clientResponse = HttpRequests.post("/user/", Crypter.encryptDecryptXOR(new Gson().toJson(data)));

服务器端(解析json,然后解密):

String s = new Gson().fromJson(data,String.class);
String decrypt = Crypter.encryptDecryptXOR(s);
String decrypted = Crypter.encryptDecryptXOR(data); 
SomeClass userData = new Gson().fromJson(decrypted, SomeClass.class);
 类似资料:
  • 这是我从mysql数据库中删除数据的代码,我得到了这个错误。 在我选择名称并尝试提交后...它给我这个错误 HTTP状态500-内部服务器错误 类型异常报告 Message内部服务器错误 描述服务器遇到内部错误,无法满足此请求。 例外 组织。阿帕奇。贾斯珀。JaspereException:java。lang.NumberFormatException:空根本原因 JAVAlang.NumberF

  • 当我尝试使用JSP运行我的Web应用程序(基本CRUD)时,GlassFish服务器返回以下消息: HTTP状态500-内部服务器错误 类型异常报告 消息内部服务器错误 说明服务器遇到内部错误,无法满足此请求。 例外 java.lang.NullPointerException 注意GlassFish Server Open Source Edition 4.1日志中提供了异常及其根本原因的完整堆

  • 下面是我的一部分。jsp。 下面是我的错误: HTTP状态500–内部服务器错误 类型异常报告 消息在行[20]处处理[/home.jsp]时发生异常 说明服务器遇到意外情况,无法满足请求。 例外组织。阿帕奇。贾斯珀。JasperException:在第[20]行处理[/home.jsp]时发生异常 17:这是添加信息页 18: Stacktrace:org。阿帕奇。贾斯珀。servlet。Jsp

  • 当我尝试使用JSP运行我的Web应用程序时,GlassFish服务器返回以下消息: 我不知道该怎么办。我认为这个错误与找不到javax有关。servlet。jsp。jstl。glassfish服务器中的jar库

  • 删除php扩展URL。//.htAccess代码 RewriteEngine on RewiteRule^dashboard$dashboard.php[L] 内部服务器错误服务器遇到内部错误或配置错误,无法完成您的请求。 请与postmaster@localhost的服务器管理员联系,通知他们此错误发生的时间,以及您在此错误发生之前执行的操作。 有关此错误的详细信息可以在服务器错误日志中获得。

  • 在尝试使用Twython进行简单的推特搜索时 我得到了这个错误: 这里可能有什么问题?