I am building an application with Spring MVC and jquery for UI. The UI developer is designing the pages using jQuery without using any server (as it is not required). The pages are integrated by developers in the application.
The issue here is that the UI designer is using relative directory path and to integrate these pages, paths need to be prefixed with spring resource path. Even the JS and CSS files are referring to images with relative directory path. Every time the UI is update same process is repeated for integration.
What I want to know is there any better approach in this case so that
the relative path used by ui developer doesn't needs to be changed every time for integration.
The spring static resource loading can still be used. <mvc:resources mapping="/res/**" location="/resources/" />
The path reference in any js or css file can also work without any changes in it.
I do not want to do anything which tightly couple it with a server. Please help.
lookup util:constant in the spring documentation and see if that is helpful.
Related
This is the the picture of my project.
I have my css file in static/css folder and I am trying to link it with my index.jsp page but it's not working.
NB : Hard refresh, cache clear everything is done and I have tried more than 10 times. :( is there any other way to link up css with spring boot application?
In the Spring-boot documentation you can read where Spring-boot reads static resources by default.
By default Spring Boot will serve static content from a directory
called /static (or /public or /resources or /META-INF/resources) in
the classpath or from the root of the ServletContext. It uses the
ResourceHttpRequestHandler from Spring MVC so you can modify that
behavior by adding your own WebMvcConfigurerAdapter and overriding the
addResourceHandlers method.
If you change the location of your static files to the default one you should be able to reach them by /css/style.css
P.S. here you can find a simple good structured example.
For me now I just put my CSS, JS, images in src/main/resources/static folder and the link is like :
/css/style.css or /js/custom.js
is working fine for spring boot application.
The solution to your problem is very simple, just add to your application.properties file (your configuration file) the next 2 lines of code:
spring.resources.chain.strategy.content.enabled=true
spring.resources.chain.strategy.content.paths=/**
this will bust the cache in your browser, and when you'll make changes regarding to static content (like: css files, js files, html files), it will take place.
Spring Boot CSS Showing up blank / not loading after trying everything
Good Luck.
We're accessing a 3rd-party iFrame (dialog) in our web app. This is loaded by javascript and served via the 3rd-party's server. If we provide them with a link to a custom CSS file we can change the appearance of the dialog.
How, in the Rails pipeline, can we create this file and then provide the 3rd-party with a URL that will, hopefully, respect (read: use) our CDN?
Does the file belong in vendor/assets/stylesheets/? I'm pretty sure that becomes part of asset pipeline as well...
Thoughts?
I'm having hard time understanding the purpose of <mvc:resources mapping="..." location=".."/>section in my configuration file.
my project structure...
--WebContent
-----META-INF
-----static
-----------images
------------js
------------css
-----WEB-INF
--------jsps
--------spring-configs
--------web.xml
I'm able to access files under images, js and css folders even when I don't specify this section in the spring servlet config file. So why do I need to specify this? What purpose does it serve exactly?
For the record, this is what I have in my config file.
<mvc:resources mapping="/static/**" location="/static/" />
You don't need it if that's where you put your resources. Everything at the root of your web application (WebContent), which isn't WEB-INF or META-INF is publicly available and the Servlet container can serve it to any client.
The <mvc:resources ... /> element is meant to serve resources which are within WEB-INF which is not available directly to clients. They must be served by your application.
Adding to what #Sotirios has answered, <mvc:resources/> can resolve static resources from Classpath resources ( for e.g., a jar file). This opens up the possibility of packaging your static resources in a self-contained jar module along with your business logic (although very few people use this approach in command based framework like Spring - this is more prevalent in Component based frameworks like JSF).
Apart from this there are other benefits of using this tag as mentioned here. I'm quoting
The cache-period property may be used to set far future expiration
headers (1 year is the recommendation of optimization tools such as
Page Speed and YSlow) so that they will be more efficiently utilized
by the client. The handler also properly evaluates the Last-Modified
header (if present) so that a 304 status code will be returned as
appropriate, avoiding unnecessary overhead for resources that are
already cached by the client
Doing a project between multiple people, and a few components (web app, services app and some others). We will be storing some information inside the Content folder of the web app so it can be accessed directly from the web server with an href, however other components outside of the web app need to access this folder as well, and since we are sharing the project between multiple people using an absolute path is not an option. What options do we have?
EDIT: Trying to explain it a little better.
What i have exactly is, a web project, a "data project" which is just a dll, a "logic" project which is another dll and a services project which is an exe/service.
Both the web project and service project consumes the methods from the logic, and the logic from the data project. Being the last one the responsable for storing data (in a database) and also in the file system.
This "filesystem" path should be configurable, and we are aiming to put it into the content folder of the web project so multimedia files can be accessed directly rather than doing a byte stream.
Now in the web.config(config file of the web app), and app.config(config file of the services app) i could set the absolute path to web/content (the same for both config files) and the data dll would use it without problems. Now the main problem is that we cannot put an absolute path in the config file because each person works on a different computer with obviously different file paths. So if i could just write something like: ~/project/Web/Content rather than C:/myfolder/stuff/blabla/project/web/content in the config files, with ~ resolving the path to the project, this is what i want! Or maybe better ideas about how to share a folder with these apps without adding absolute paths hardcoded somewhere.
What you want to use is:
Server.MapPath("/Content/filepath.ext");
This will give you the absolute path of a file based on it's position within the website, in this case, from the /Content directory.
For a program external to the website, you have a couple options;
The easiest to implement might be a simple configuration value in the external program which points to the directory. My guess is you've already decided that's not ideal, but it may be the quickest way.
Alternatively, there's a Microsoft .NET assembly which gives you easy access to IIS information (I can't recall its name off the top of my head!). You could use this assembly to find the appropriate website, and retrieve its root directory. I'll see if I can find it and get an example, or maybe someone else will see this and post an answer with that information.
Please check the following method "ResolveClientUrl"
MSDN
Use the ResolveClientUrl method to return a URL string suitable for use by the client to access resources on the Web server, such as image files, links to additional pages, and so on.
http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveclienturl.aspx
I am working on a project that is primarily ASP.NET based. The main project is meant to be deployed to multiple locations for different clients, so one client might be located at website.com/client1 and another at website.com/client2. Within the application, we regularly use the application root operator ~ to get the path to a resource.
We also have a bunch of Flex applications that get deployed in there, and many rely on web services within the ASP.NET application. What I'm after is a way to reference the services relative to the application root. Here's an example of the location of some files for two client deployments:
Client A
website.com/clientA/swf/FlexApplication.swf
website.com/clientA/services/webService.asmx
Client B
website.com/clientB/swf/FlexApplication.swf
website.com/clientB/services/webService.asmx
FlexApplication and webService are both exactly the same, so what I want to do is something like this in the Flex code:
var myService:CustomService = new CustomService(~/services/webService.asmx);
myService.callMethod("Test");
I would like to avoid using relative paths for the usual reasons. Is there a good way to do this or a good way to pass the root url to the flex application from ASP.NET? Thanks in advance.
Its definitely a good idea to avoid relative URL's. The easiest way is to pass the information in via Flash Vars in the HTML embed statement.
Check out Adobe's documentation on using FlashVars with Flex: http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_3.html
Summary:
Add a line to the HTML embed statement like this:
<param name='flashVars' value='serviceRoot=/myserviceRoot'/>
Then access it in Flex via the mx.core.Application.application.parameters accessor
import mx.core.Application;
var parameters:Object = Application.application.parameters;
var serviceRoot:String = parameters['serviceRoot'];
relative to the application root
Flex knows nothing about the application root of a ASP.NET application. The only thing that the Flex app knows is the URL that it is served from. It does not know the URL of the page. Keep in mind that the URL of the page and the URL of the SWF are not the same.
It appears, given your directory structure, that you can use the SWF's URL to get the information you're after.
In a Flex 3 Application, you can get use the url property of the Application tag:
(Application.application as Application).url
In a Flex 4 Spark application, you can also use the url property of the Application Tag, but you have to get it differently:
(FlexGlobals.topLevelApplication as Application).url
Then you can parse it with URLUtils to get your directory structure. Probably store that as a global variable in your Flex application somehow and use it to construct the URL for the service calls you are making to the remote server.
I use this handy little utility to get URL information via javascript inside the .swf.
http://www.flexpasta.com/index.php/category/utility-classes-that-help-you-deal-with-string-numbers-arrays-and-objects-in-actionscript/