我一直在寻找年龄问题的答案,并且可以找到。 真正希望的人能够帮助
My structure:
WebContent
- resources
- css
- style.css
- WEB-INF
- web.xml
template.html
web.xml
<servlet>
<servlet-name>RestletServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>RestletServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
Application.java
String ROOT_URI = "C:/projects/testsite/WebContent/"
try {
configuration.setDirectoryForTemplateLoading(new File(ROOT_URI));
configuration.setObjectWrapper(new BeansWrapper());
} catch (IOException e) {
e.printStackTrace();
}
router.attach("/resources", new Directory(getContext(), LocalReference.createFileReference(ROOT_URI)));
router.attach("/index", IndexResource.class);
When I go to URL: localhost:8080/testsite/index I get the template file with it populated with the correct data. However the CSS is not loaded. I can see in my eclipse console that restlet is trying to fetch it but I it get a 404
127.0.0.1 8080 GET /testsite/resources/css/style.css - 404
As you can see above I am trying to use the Directory
class to load my css directory but has no effect. Maybe this is wrong!?
Is there a way in which css does not go through restlet?
It would be good if ROOT_URI
was relative instead of the absolute path. Is there an easier way to get the path of my location?