【发布时间】:2015-02-28 06:12:27
【问题描述】:
我有一个 JAVA-EE 项目,它在我的 Intellij 13.1.4 中使用“restlet-2.2”框架。
我想将此项目部署到 apache tomcat 服务器,但我遇到了一些问题。
项目结构
1.我有一些 JAVA 类,它们基本上是不同的 Web 服务。所有这些类都扩展了 ServerResource 类。这些类内部有 @Get 方法,它们将响应客户端请求。
2.然后我有一个扩展 Application 类的类 MyServer 并且在 MyServer 中我有一个 Router 类对象,它基本上将请求路由到适当的 Web 服务,具体取决于URI。
3.web.xml - Intellij 默认创建一个带有 version="3.1" 的 web.xml 并在其中添加 nothing。所以我修改了那个web.xml(在下面添加web.xml)
我已经完成了工件配置,并且在我的“战争爆发”中我有以下结构
WEB-INF
--classes
-----| All compiled class files
--lib
-----| restlet jar files and json jar files (org.json.jar org.restlet.jar org.restlet.ext.json.jar org.restlet.ext.servlet.jar)
--web.xml
当我把这个爆炸的战争放在我的 apache tomcat webapps 文件夹中并重新启动 tomcat 时,我就可以访问 html/css/js 文件了。但是我的 AJAX 调用总是给出 ERROR 404。我已经尝试了 stackoverflow 和其他网站的所有解决方案,但没有任何帮助。
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!-- Application class name -->
<context-param>
<param-name>org.restlet.application</param-name>
<param-value>
MyServer
</param-value>
</context-param>
<!-- Restlet adapter -->
<servlet>
<servlet-name>ServerServlet</servlet-name>
<servlet-class>
org.restlet.ext.servlet.ServerServlet
</servlet-class>
</servlet>
<!-- Catch all requests -->
<servlet-mapping>
<servlet-name>ServerServlet</servlet-name>
<url-pattern>/Projects/*</url-pattern>
</servlet-mapping>
</web-app>
MyServer 类
Router classpublic class MyServer extends Application{
public static void main(String []args)
{
Component component = new Component();
component.getServers().add(Protocol.HTTP, 8080);
Application application = new MyServer();
// Attach the application to the component and start it
component.getDefaultHost().attach(application);
try {
component.start();
} catch (Exception e) {
e.printStackTrace();
}
}
//Method for attaching the URIs for web services
public synchronized Restlet createInboundRoot()
{
Router router = new Router(getContext());
//System.out.println("In router");
//Attaching URIsl
router.attach("/Projects/{projectID}/Enclosures/{enclID}/getStructure", StructureCalculations.class);
}
}
我的 AJAX 调用 URI 看起来像这样
http://localhost:8080/Projects/p1/Enclosures/e1/getStructure?param1=x¶m2=y
【问题讨论】:
标签: xml tomcat restlet intellij-13