本文介绍了在glassfish上存储图像,CSS和JavaScript文件的位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在发布这些问题之前,我已经仔细查看了 (相信我:),我仍然感到困惑。以下是该场景:使用Restlet 2.0在glassfish v3上托管J2EE Web应用程序freemarker模板文件位于/ WEB-INF文件夹中。模板链接到jQuery / JavaScript文件,一些静态图像和使用相对URL的样式表。



由于将它们存储在/ WEB-INF中并不是一个好习惯(正如Web上的许多地方所述),所以我将这些文件移到了WebContent文件夹中

  
WebContent:
+ - 图片
-.jpg,.gif文件
+ - 样式
-myStyle.css
+ - 脚本
+ - jQLabel
+ - mColorPicker
+ - 图片
+ - -javascripts
-.js文件

我将它们引用到freemarker模板/ html中:

 < link rel =stylesheettype =text / csshref =$ {baseRef} / Styles / myStyle.css/> 

其中 $ {baseRef} 是根该网站的参考。该网站部署在/ Winbook。因此,本地主机上的CSS的URL如下所示:


$ b < - 使用GET检索



问题):

对于上面的每个资源,我得到一个404 :(我不确定这是真的应该如何存储css ,图片或脚本以及WebContent文件夹是否是存储它的好地方。



问题:


  1. 为什么上述不能正常工作?我的意思是必须有一个错误,我不知道它是什么:)

  2. 什么是将上述文件存储在Web服务器/ glassfish上的最佳位置

  3. 如果在.war中部署这些资源(在HTML / freemarker模板中),我该如何引用它们? (如果它们被放置在WebContent中,它们将被部署到war文件中,对吗?这是'合法的'还是很好的做法?似乎有异味:)

  4. 我们是否需要创建替代文档根源于glassfish for all 这样的资源(或Restlet中的等效Directory类?)

  5. 对于这样的部署,最佳方式/地点是什么?为基于Intranet的应用程序无缝地定位资源?基于JNDI的查找? (我不知道这样做会如何,另一个问题可能就是这样)

我非常困惑!已经有一段时间了,因为我必须编写完整的端到端Web应用程序,而这通常由其他来处理:)



谢谢!

解决方案

我可能迟到发布一个答案,但在这里。正如我所提到的那样,Restlet拦截URL并且您必须使用Directory类来返回静态内容 - 对于每个文件夹,用路径war:///或war:/// images /等初始化。

不工作的原因是Restlet的路由问题 - 目录文件夹是URL的代码顺序中的last。目录是使用Template.MODE_STARTS_WITH创建的,其他(即Restlets或其他资源)是Template.MODE_EQUALS



您应该手动更改路由顺序或将其推送到



希望能帮助任何人解决同样的问题。



以下是Jerome回答的相关问题:


I've looked around a lot (trust me :) before posting this questions and I'm still confused. Here's the scenario:

Hosting a J2EE web-app on glassfish v3 using Restlet 2.0 The freemarker template files are located in the /WEB-INF folder. The templates link to jQuery/javascript files, some static images and stylesheets using relative URLs.

Since it's not a good practice to store them in /WEB-INF (as stated at many places on the web) I moved the files to the WebContent folder


WebContent:
+--Images
   -.jpg, .gif files
+--Styles
   -myStyle.css
+--Scripts
   +--jQLabel
   +--mColorPicker
      +--Images
      +--javascripts
         -.js files

I refer to them in the freemarker template/html as:

<link rel="stylesheet" type="text/css" href="${baseRef}/Styles/myStyle.css"  />

where ${baseRef} is the Root Reference of the site. The site is deployed at /Winbook. So the URL on the localhost for the css looks like this:

http://localhost:8080/Winbook/Styles/winbookwall.css <-- retrieved using a GET

Problem(s):

For each of the above resources I get a 404 :( I'm not sure if this is really how one should store css, images or scripts and whether the WebContent folder is a good place for it be stored.

Question(s):

  1. Why is the above not working? I mean there has to be a mistake and I just don't know about it :)
  2. What is the best place to store the above files on the web server/glassfish?
  3. How do I refer to those resources (in the HTML/freemarker template) if they are deployed in the .war? (They will get deployed in the war file if they are placed in WebContent, right? Is this 'legal' or good practice? Seems to smell :)
  4. Do we have to create alternate doc roots in glassfish for all such resources (or the equivalent Directory class in Restlet?)
  5. What is the 'best' way/place of/for such a deployment for an intranet based application to seamlessly locate the resources? JNDI based lookup? (I don't know how that would work, another question probably on SO ;)

I am totally confused! It's been a while since I had to write a full end to end web app and this was usually taken care of by the 'others' :)

Thanks!

解决方案

I'm probably late on posting an answer to this but here it is. As I mentioned it Restlet intercepts the URLs and you HAVE to use the Directory class to return static content - initialized with the path "war:///" or "war:///images/" etc., for each of the folders.

The reason it wasn't working was with the Routing issues of Restlet - The directory folder was 'last' in the code order of URLs. Directories are created with Template.MODE_STARTS_WITH and the others (i.e., Restlets or other resources) are Template.MODE_EQUALS

You should either change the order of routing manually or push it at the top of the list of URIs when routing.

Hope that helps anyone stumbling on the same problem.

Here is the related question that Jerome answered: Restlet Routing Nightmare

这篇关于在glassfish上存储图像,CSS和JavaScript文件的位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-23 02:36