我的Java代码中每次都找不到页面。 我的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_3_1.xsd"
id="WebApp_ID" version="3.1">
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
我的应用程序配置文件代码如下:
@javax.ws.rs.ApplicationPath("/restapi")
public class ApplicationConfig extends Application {
@Override
public Set<Class<?>> getClasses() {
Set<Class<?>> resources = new java.util.HashSet<>();
addRestResourceClasses(resources) ;
return resources;
}
private void addRestResourceClasses(Set<Class<?>> resources) {
resources.add(ws.TodolistRestful.class) ;
}
}
如果我尝试使用http://localhost:8080/Rest/restapi/todolist/findallxml
,那么每次都会找不到它。
这里的todolist和findallxml如下代码:
@Path("/todolist")
public class TodolistRestful {
@PersistenceUnit(unitName = "todolist")
private TodolistModel tm = new TodolistModel();
@GET
@Path("/findallxml")
@Produces(MediaType.APPLICATION_XML)
public List<Todolist> findAll_XML () {
return this.tm.findAll() ;
}
}
我的Todolist类代码如下:
@Entity
@Table(name = "todolist", catalog = "angular_java")
@XmlRootElement(name = "todolist")
public class Todolist implements java.io.Serializable {
private Integer id;
private String taskName;
private char taskDone;
private Date taskCreated;
private boolean taskDeleted;
private Date taskUpdated;
public Todolist() {}
public Todolist(String taskName, char taskDone, Date taskCreated, boolean taskDeleted, Date taskUpdated) {
this.taskName = taskName;
this.taskDone = taskDone;
this.taskCreated = taskCreated;
this.taskDeleted = taskDeleted;
this.taskUpdated = taskUpdated;
}
@Id
@GeneratedValue(strategy = IDENTITY)
@Column(name = "id", unique = true, nullable = false)
public Integer getId() {
return this.id;
}
public void setId(Integer id) {
this.id = id;
}
...
}
这是一个Todolist类,由Hibernate自动生成。