English 中文(简体)
通过休息室进行的预防工作
原标题:Prevent css going through restlet

我一直在寻找年龄问题的答案,并且可以找到。 真正希望的人能够帮助

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?

问题回答

我首先注意到,由于你的名录以“档案”程序为基础,申请的集装箱必须申报该客户的链接。 这是在网上配置文件内进行的:

<servlet>
    <servlet-name>RestletServlet</servlet-name>
    <servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
    <init-param>
        <param-name>org.restlet.application</param-name>
        <param-value>test.MyApplication (actually the full name of your Application</param-value>
    </init-param>
    <init-param>
        <param-name>org.restlet.clients</param-name>
        <param-value>FILE</param-value>
    </init-param>
 </servlet>

如果没有这一指示,我认为你的记录中有一些内容,例如:

ATTENTION: The protocol used by this request is not declared in the list of client connectors. (FILE)

说到这一点,利用“档案”程序为你的固定档案服务,你的申请与你的档案系统有关。 你可以在内部为这些档案服务,也就是说,让集装箱在应用WAR(可能不舒服)内寻找固定资源。 你们只能以“战争”议定书为基础:

router.attach("/resources", new Directory(getContext(), "war:///"));

我希望这将有助于你。

Best regards, Thierry Boileau

我开始工作,我不得不把这一制图纳入我的网络。

 <servlet-mapping>
 <servlet-name>default</servlet-name>
 <url-pattern>/resources/*</url-pattern>
</servlet-mapping>




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签