how to use css files spring - css

am developing a java web application using netbeans ide(jdk 1.6, tomcat 7, mysql, spring 3.0.2, hibernate).I have a multiactioncontroller named 'maincon'. In web.xml, the home page is set as redirect.jsp. the redirect.jsp will redirect the request to index page with the help of multiaction controller. now how can I use css files in this index.jsp
I have a 'indexpageStyle.css' file in the WEB-INF/resources/styles/. if more information is required to answer this, please ask.
Thanks in advance

Browsers do not have direct access to resources under WEB-INF; if you really need it there (which would be weird) you'll need to stream it back yourself.
Otherwise, move it out of there, include it as a regular CSS resource, but generate the file's path using or the Spring equivalent.

you can use like this inside jsp
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/source/css/reset.css">

Related

How to include CSS in Symfony 5

I am building a Symfony 5 app and want to use CSS inside my twig templates. My stylesheet is at public/css/styles.css and so I try to use it in my twig template with the line <link href="{{ asset('css/styles.css') }}" rel="stylesheet" type="text/css"/>. This works locally but once I deploy it to the Google Cloud Platform the server can no longer find it. The console shows a 404 error when trying to find the stylesheet. Where does Symfony want me to put my css files?
This feels like it should be very simple but I'm totally at a loss and feel like I'm missing something stupid. The documentation only really talks about Encore and that seems like such overkill for using a single CSS file in a twig template.
(sorry i cant comment because low reputations, thatswhy i need to take an answer)
At first, the location of your css is correct. Also the usage of your link tag looks fine. Now the question is: what is the correct error message, or better where looks the browser to your file?
I think the browser want to take your file from root, not from public folder. If you can answer this with yes, you have to check your .htaccess file and/or linking from webspace to startfolder (public) in this cause.
It works in localhost because the symfony dev-server take this work for you.
Got the CSS working. I think what did it was telling app.yaml to put the css in the public folder.
handlers:
- url: /css
static_dir: public/css
Then instead of loading using the asset() function, I included the css with:
<link href="/css/styles.css" rel="stylesheet" type="text/css"/>
That way, the css folder I had in public locally was put in public when deployed to the GCP.

how to link css file from outside web application

Simple as title says, how do I include a css file that is found two parent folders up from the actual web application itself?
I have tried adding the file as a link to the web project and then referencing it like that and it dose not work
<link rel="stylesheet" href="../../mystyle.css" /> would literally move up two folders on your server. You may be better off with using the full path: <linke rel="stylesheet" href="/folder1/folder2/mystyle.css" /> - which all assumes that the path you need to get to is accessible to the web server.
Since the page comes from the server I would read the physical file and stuff that onto the page as part of the server script such as:
<style>
<?= css_file_content ?>
</style>
If in a parent folder, it may be outside the hosted path making it inaccessible to the client. But it is not inaccessible to the server-side script.
Visit: http://www.w3schools.com/css/css_howto.asp
You can add inline css if external doesn't work

I need to add css to my rails application in assets pipeline?

I have a rails app I put my index.html in public folder and it shows when i go to port 3000 but it doesn't show it with css, I have my css folder and i tried putting it into assets stylesheets but nothing is happing? where do i put my folder with all the css files in it? would i need to change the way my index.html referances my css files?
for now my index.html in public folder references the css files like this <link href="css/styles.css" rel="stylesheet">
i've looked into some tutorials but their a bit complex in understanding
Things put in the public folder won't be processed by the asset pipeline. This isn't the "rails way" at all, but you can just move your .css to your public folder and call it like you're calling it now.
To gain access to the asset pipeline the quickest way I can think of is to just scaffold generate something, fill in the view with your HTML and then you can call via asset pipeline. However by default the root route isn't set so you'll have to navigate to localhost:3000/whatever-controller-you-generated-here
I highly recommend reading this guide before you go much further http://guides.rubyonrails.org/
First of all if you are using rails then why are you using static page like this. If you really want to use this then you have to specify stylesheet like this
<link href="/assets/application.css" rel="stylesheet" />

Spring MVC Resources

I am trying to link my static elements in with Spring MVC using the resources tag - what I am not able to figure out is where to place them.
I am publishing my links as -
<link rel="stylesheet" href="/css/elements.css">
I have placed the files under -
WebContent/resources/css/elements.css
The resources tag I am using in my servlet is -
<mvc:resources location="/css/**" mapping="/resources/css/"/>
Am i missing something?
You inverted the two attributes. locations is where the files are in the web app root. mapping is the url-pattern used to access the resources from the browser. So the configuration should be
<mvc:resources location="/resources/css/" mapping="/css/**"/>
As explained in the documentation.
You have your resources in "resources" folder, so you added following line in dispatcher xml.
<mvc:resources location="/css/**" mapping="/resources/css/"/>
And this resources folder must have been in "webcontent" folder.
Then you need to access the resources by using context path.
<link rel="stylesheet" href="${pageContext.request.contextPath}/resources/css/elements.css">
Give this a try. It should work.
Found the mistake .. using c:url to publish the absolute path helped :)
I am now publishing my URLs as
<link rel="stylesheet" href="<c:url value="/css/slideshow.css" />">
If you are using locations relative to root context of Tomcat, then you need to do it like this. The difference between this and the other answers is that I am including the application context in the location mapping:
<mvc:resources location="/webapp-name/resources/" mapping="/resources/**"/>
The attribute "mapping" is relative to classpath whereas "location" is relative to root of Tomcat. (NOTE: these are not 'relative' urls)
This config will provide access to resources in sub-folders, such as /resources/css/*

Tapestry 5, loading css from filesystem

We are creating a Tapestry 5 webapp with an external designer creating and maintaining the css-files of the application.
We would like him to be able to make changes to the css-files without the need to change the webapp, prefarably in the configurable path in the filesystem.
So what would the best way to do this with Tapestry 5?
There is a JIRA for the ability to use a filesystem asset. Someone has posted patches that should let you do it but it hasn't made it into a release yet. If you do that, you could use #IncludeStyleSheet(value={"file:path_to_css_file"}) in your layout template.
An alternate way would be to stream it using a method like this one. The last paragraph suggests that you can include a streamed response in your template so in this case you could do <link rel="stylesheet" type="text/css" href="${externalStylesheet}"/>. Then create a streamed response that reads the stylesheet from a known path on the server. Or you could store it in a blob in the database and stream from there - that way you could also create a page to let the designer upload new versions.

Resources