如何消费新泽西Web服务响应

问题描述 投票:0回答:1

我已经使用JAX和java泽西Web服务,它的工作,当我粘贴我的浏览器我的web服务的URL它表明了我数据库的XML。

现在我想消费这个XML,我希望能够为为例采取图片的路径,并显示在我的主页,取的名字和所有其他的东西,让像Instagram的饲料。

我想显示在XML中的每个对象的图像,并在饲料中的其他信息。

我很抱歉,如果这个问题听起来很愚蠢,但它是我的第一次

我收到的XML是这样的对象列表:

 <image>
 <category>automobile</category>
 <date>2019-40-08 02:40:18</date>
 <description>lamborghini lp-750sv </description>
 <name>New car</name>
 <PATH>
 C:\Users\ilyas\Desktop\PROJETS\workspace      eclipse\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\SupPinterest\uploads\automobilelambosv750.jpg
 </PATH>
 <username>ilyas110298</username>
 </image>

这是我的image.java:

 package com.servlet;

 import java.io.Serializable;

 import javax.xml.bind.annotation.XmlRootElement;
 import javax.servlet.http.*;

 import javax.xml.bind.annotation.XmlElement;

 @XmlRootElement(name = "image")
 public class image extends HttpServlet implements Serializable {
String name , description , PATH , date , category , username;

public image() {

}
public image(String name, String description, String pATH, String date,                String category, String username) {
    super();
    this.name = name;
    this.description = description;
    PATH = pATH;
    this.date = date;
    this.category = category;
    this.username = username;
}
public String getName() {
    return name;
}
public String getDescription() {
    return description;
}
public String getPATH() {
    return PATH;
}
public String getDate() {
    return date;
}
public String getCategory() {
    return category;
}
public String getUsername() {
    return username;
}
@XmlElement
public void setName(String name) {
    this.name = name;
}
@XmlElement
public void setDescription(String description) {
    this.description = description;
}
@XmlElement
public void setPATH(String pATH) {
    PATH = pATH;
}
@XmlElement
public void setDate(String date) {
    this.date = date;
}
@XmlElement
public void setCategory(String category) {
    this.category = category;
}
@XmlElement
public void setUsername(String username) {
    this.username = username;
} 
}

这里是我imageDAO:

package com.servlet;

import java.sql.Connection;
import java.sql.*;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import java.util.AbstractList;
import java.util.ArrayList;
import java.util.List;
public class imageDao {


public List<image> getAllImageList(){
    List<image> imageList = null;
    //boolean st =false;
      try{

     //loading drivers for mysql
         Class.forName("com.mysql.jdbc.Driver");

     //creating connection with the database 
         Connection con=DriverManager.getConnection
                        ("jdbc:mysql://localhost:3306/supdb?            useUnicode=true&useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC","root","ilyas");
         Statement stmt = con.createStatement();
         ResultSet rs =stmt.executeQuery("select * from image");
         imageList = new ArrayList<>();
         while(rs.next()) {
             String name = rs.getString(1);
             String description = rs.getString(2);
             String PATH = rs.getString(3);
             String date = rs.getString(4);
             String category = rs.getString(5);
             String username = rs.getString(6);

             imageList.add(new image (name, description, PATH, date, category, username));

         }
         rs.close();
         stmt.close();
         con.close();

         return imageList;
      }catch(Exception e)
      {
          e.printStackTrace();
      }

        return imageList;
}
}

最后我imageSERVICE:

package com.servlet;
import java.util.List;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlRootElement;

@Path("/imageservice")
@XmlRootElement
public class imageService {

imageDao imageDAO = new imageDao();
@GET
@Path("/imageList")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
public List<image> diplayImage(){
    return imageDAO.getAllImageList();
}
}

我使用Eclipse和Apache和MySQL

当我使用一个API测试仪和粘贴API URL(http://localhost:8080/SupPinterest/image/imageservice/imageList)我得到的错误

javax.servlet.ServletException: 
org.glassfish.jersey.server.ContainerException: java.lang.NoSuchMethodError: 
com.fasterxml.jackson.core.JsonFactory.requiresPropertyOrdering()Z
rest jsp java-ee jersey
1个回答
0
投票

我找到了解决方法,依赖错误的地方

here is a picture of the dependencies i put in web-inf/lib

你只需要通过一个相同的版本安装所有的依赖关系之一,我删除了所有的依赖,我开始运行该程序获得的相关性错误,并寻找罐子,直到它的工作

© www.soinside.com 2019 - 2024. All rights reserved.