我的 gwt 项目有一些问题,我使用 eclipselink 和 hsqldb 作为数据库。
这是我的代码: Project.java:
package com.example.client;
public class Project implements EntryPoint {
private final EmployeeServiceAsync eService = (EmployeeServiceAsync) GWT.create(EmployeeService.class);
[...] some GWT code
@Override
public void onModuleLoad() {
eService.createemployee(new AsyncCallback<Void>() {
@Override
public void onFailure(Throwable caught) {
Window.alert("Fail!");
}
@Override
public void onSuccess(Void result) {
//nothing
}
});
但每次都失败并出现以下警告:
WARNING: No file found for: /project/employeeService
那么我怎样才能正确调用这个方法呢?
EmployeeService.java
package com.example.client.service;
@RemoteServiceRelativePath("employeeService")
public interface EmployeeService extends RemoteService{
public void createemployee();
}
EmployeeServiceAsync.java
package com.example.client.service;
public interface EmployeeServiceAsync {
void createemployee(AsyncCallback<Void> callback);
}
EmployeeServiceImpl
package com.example.server.ServiceImpl;
public class EmployeeServiceImpl extends RemoteServiceServlet implements EmployeeService {
private static final long serialVersionUID = 1L;
public void createemployee() {
javax.persistence.EntityManagerFactory emf = Persistence.createEntityManagerFactory("ronfPU");
javax.persistence.EntityManager em = emf.createEntityManager();
try {
// Create new Employee
em.getTransaction().begin();
Employee e1 = new Employee();
e1.setName("admin");
e1.setSurname("admin");
e1.setUsername("admin");
e1.setPassword("admin");
em.persist(a1);
em.getTransaction().commit();
} finally {
em.close();
}
}
}
Employee类存储在com.example.shared.entity中;我认为persistence.xml 和project.gwt.xml 没问题,但我不确定web.xml代码:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5" xmlns="http://java.sun.com/xml/ns/javaee">
<!-- Servlets -->
<servlet>
<servlet-name>employeeServiceImpl</servlet-name>
<servlet-class>
com.example.server.ServiceImpl.EmployeeServiceImpl
</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>employeeServiceImpl</servlet-name>
</servlet-mapping>
<!-- Default page to serve -->
<welcome-file-list>
<welcome-file>Project.html</welcome-file>
<url-pattern>/com.example.client.Project/employeeService</url-pattern>
</welcome-file-list>
</web-app>
首先应该是,如果我理解正确的话,源自@RemoteServiceRelativePath("employeeService")
; 而<servlet-class>
派生自存储在服务器端的类,它扩展了 RemoteServiceServlet;<servlet-mapping>
应该是一样的<servlet-name>
,在这里,在<url-pattern>
,我不确定我写了什么。
您如何建议正确运行此代码?先感谢您!