如何解决使用tomcat 9.0.38的Eclipse中的HTTP Server 500
这是web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
id="WebApp_ID" version="4.0">
<display-name>REST_API_Ecommerce_App</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>JaxRsApp</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.oracle.api</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JaxRsApp</servlet-name>
<url-pattern>/onlineapi/*</url-pattern>
</servlet-mapping>
</web-app>
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import com.oracle.dao.ProductDao;
import com.oracle.model.Product;
@Path("/products")
public class ShoppingCatalogue {
@GET
@Produces(MediaType.APPLICATION_JSON)
public List<Product> getAllProducts(){
ProductDao dao=new ProductDao();
return dao.getAllProducts();
}
}
Mediatype.APPLICATION_JSON解决了HTTP_500错误,没有任何说明,控制台也没有错误。
productdao类如下
import java.util.ArrayList;
public class ProductDao {
private ArrayList<Product> productList = new ArrayList<>();
{
Product p1 = new Product(101,"i3",30838);
Product p2 = new Product(102,"i5",130838);
Product p3 = new Product(103,"i7",230838);
Product p4 = new Product(104,"i9",330838);
Product p5 = new Product(105,"i9 10th",430838);
productList.add(p1);
productList.add(p2);
productList.add(p3);
productList.add(p4);
productList.add(p5);
}
public ArrayList<Product> getAllProducts() {
return productList;
}
}
产品类别如下:
import javax.xml.bind.annotation.XmlRootElement;
@XmlRootElement
public class Product {
private int productId;
private String productName;
private float productPrice;
public int getProductId() {
return productId;
}
public void setProductId(int productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public float getProductPrice() {
return productPrice;
}
public void setProductPrice(float productPrice) {
this.productPrice = productPrice;
}
public Product(int productId,String productName,float productPrice) {
super();
this.productId = productId;
this.productName = productName;
this.productPrice = productPrice;
}
}
我无法弄清为什么我继续通过APPLICATION_XML或APPLICATION_JSON而不是TEXT_HTML出现HTTP 500错误。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。