This is where i put my css file:
This is how i register this resource:
#Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
}
This is how i references this css from the JSP:
<link type="text/css" href="/css/bootstrap.css" rel="stylesheet"/>
I can see the JSP page with content but without styling.
I think the error is while referencing but i cant find it. I have tried also these, but does not work:
<link type="text/css" href="../css/bootstrap.css" rel="stylesheet"/>
<link type="text/css" href="/resources/css/bootstrap.css" rel="stylesheet"/>
<link type="text/css" href="<%=request.getContextPath() %>/css/bootstrap.css" rel="stylesheet"/>
<link type="text/css" href="<%=request.getContextPath() %>/resources/css/bootstrap.css" rel="stylesheet"/>
Any idea?
EDIT: Now i have moved the css folder to WebContent. It seems like this:
It still does not work. What should i register for the ResourceHandler?
registry.addResourceHandler("/WEB-INF/**").addResourceLocations("/WEB-INF/"); ?
How should i reference the css from the JSP?
The resource handler doesn't look for resources on the class path, by default. It looks for them in the webapp.
Create a folder called resources and put it in /src/main/webapp. Then put your css, js, etc. folders in there.
The files under src cannot be accessed on default condition , you should put these assets into WebContent directory.
Resources usually means config proppertis like properties and xml, they will be used by the
java code, assets usually mean that can be accessed by the browser directly,Notice that WEB-INF is protected,you need to put your css directory under WebContent, except for WEB-INF
for exampel,you can put your css directory under /WebContent/assets/
And add these code at the head of your jsp pages
<%
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ request.getContextPath();
%>
<link type="text/css" href="<%=basePath%>/assets/css/bootstrap.css" rel="stylesheet"/>
It's not good to use relative path!!
Related
I have multiple spring MVC project that I will need to combine into one...
but say I have two folders of static resources that conflict, so i need to keep them separate:
What i do is declare two resource mapping:
<mvc:resources location="/resources/web1" mapping="/web1/**"/>
<mvc:resources location="/resources/web2" mapping="/web2/**"/>
and in my web1 jsp I do:
<link href="/web1/css/test.css" rel="stylesheet">
<link href="/web1/css/test1.css" rel="stylesheet">
<link href="/web1/css/test2.css" rel="stylesheet">
but what if i need to group my jsp, say i have web1a.jsp, web1b.jsp, web1c.jsp, and i want them all to use the web1/ resource mapping.
Is there a faster way to declare it, like a property that i can put on top of the JSP to declare that the root source is web1 instead of manually adding "web1/" for each tags? Something like:
all jsp that uses web1,
<%#root="web1/" %>
<link href="/css/test.css" rel="stylesheet">
<link href="/css/test1.css" rel="stylesheet">
<link href="/css/test2.css" rel="stylesheet">
so that i could retain the original reference without modifying each individual tags
thanks
I've a Java WebApp. I have put some attributes inside the context and init params to get them when I needed.
Content of head.jspf:
<link href="${initParam['bootstrap_css_cdn']}" rel="stylesheet" media="screen">
<link href="${applicationScope['css_dir']}basic.css" rel="stylesheet" media="screen">
From index.jsp, if I do this:
<jsp:include page="WEB-INF/jspf/head.jspf" />
it works perfectly!
But if I do this:
<jsp:include page="${applicationScope['headURL']}"
it doesn't work at all (the "headURL" variable is a string with the right URL). I mean, the jspf is included but, for example, the following code is written in the final html code literally:
${applicationScope['css_dir']}
What am I doing wrong?
#JBMizet wrote in a comment:
JSPF files are not compiled. They're supposed to be included statically, not dynamically (i.e. with <%#include %>). Change the extension to .jsp if you want a dynamic include.
I'm trying to convert a docx file to an HTML file using the given sample program.
The sample suggests:
String userCSS = "html, body, div, span, h1, h2, h3, h4, h5, h6, p, a, img,
ol, ul, li, table, caption, tbody, tfoot, thead, tr, th, td " +
"{ margin: 0; padding: 0; border: 0;}" +
"body {line-height: 1;} ";
htmlSettings.setUserCSS(userCSS);
Even though setUserCSS is a depreciated method.
This works fine, but I have my own css file that I would like to use.
I would like to avoid extracting it as a string from the file where possible.
As well as this, I would like to combine multiple css files such that the top of the resultant output html contains:
<link rel="stylesheet" type="text/css" href="stylesheet1.css"/>
<link rel="stylesheet" type="text/css" href="stylesheet2.css"/>
<link rel="stylesheet" type="text/css" href="stylesheet3.css"/>
in the head.
That, or finding an alternative to the setUserCSS method that I can call on the HTMLSettings class.
Couldn't find much for this case, only for the other way around. Any solution is appreciated. Thanks.
I don't know which language are you using to write such kind of program. But you can do that by just writing a function that would convert the path of a file into css link.
For example:
htmlSettings.loadCSS('path/stylesheet1.css');
this will converted to
<link rel="stylesheet" type="text/css" href="path/stylesheet1.css"/>
The focus of docx4j's HTML output is on creating CSS based on the formatting in the document.
That said, if the HTML is being created via XSLT, the relevant code is in the createStyleElement method in XsltHTMLFunctions.java
If you are using the non-XSLT approach, it is in HTMLExporterVisitorDelegate.
I am trying to use css file from my jsp pages but page does not see the css codes.
this is my .jsp file;
<html class="no-js" lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Foundation | Welcome</title>
<link rel="stylesheet" href="/sources/css/foundation.css" />
<script src="/sources/js/vendor/modernizr.js"></script>
</head>
<body>
this is my configuratin file
#Configuration
#ComponentScan("com.sprhib")
#EnableWebMvc
public class BaseTestConfig {
#Bean
public UrlBasedViewResolver setupViewResolver() {
UrlBasedViewResolver resolver = new UrlBasedViewResolver();
resolver.setPrefix("/WEB-INF/pages/");
resolver.setSuffix(".jsp");
resolver.setViewClass(JstlView.class);
return resolver;
}
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/sources/**").addResourceLocations("/sources/");
}
}
The webapp is not deployed as the root webapp. So it has a "context path". The path to access the index.html file which is at the root of your webapp, for example, is in fact something like
http://localhost:8080/myfirstwebapp/index.html
This is what the location bar of your browser contains, and /myfirstwebapp is the context path of your application.
So, if you page contains href="/sources/css/foundation.css", the browser will try to load the css file from
http://localhost:8080/sources/css/foundation.css
and not from
http://localhost:8080/myfirstwebapp/sources/css/foundation.css
You thus need to prepend the context path to all the absolute URLs in your webapp. Using the JSTL:
href="<c:url value='/sources/css/foundation.css'/>"
Without the JSTL:
href="${pageContext.request.contextPath}/sources/css/foundation.css"
Remove the / in /sources. This will work
Try to call those css directly through your web browser with full URL path.
It depends on what's your application path defined in your Tomcat or web server.
If it's mapped like http://yourdomain.com/ ( root ), it should be http://yourdomain.com/sources/css/foundation.css, but if it's mapped like http://yourdomain.com/test or something, URL for CSS should be http://yourdomain.com/test/sources/css/fundations.css.
You may use either relative pass for those, or introduce PATH variable so that link always created like http://yourdomain.com/PATH/sources/css/foundations.css in the source code.
I need to make a link which opens print version of current page in a new tab. I already have correspondent css-file. But I don't know how to specify when this file should be used instead of standard.
The simplest way is quite good. If I was using JSP I would simply add get parameter to print-link URL. Is there any way to achieve similar results with jsf?
Use EL to specify the CSS file dynamically, here's an example which checks the presence of the print request parameter (thus, <h:outputLink value="page.jsf?print" target="_blank"> would suffice):
<link rel="stylesheet" type="text/css" href="${not empty param.print ? 'print.css' : 'normal.css'}" />
You can also retrieve it as a bean proprerty the usual JSF way:
<link rel="stylesheet" type="text/css" href="<h:outputText value="#{bean.cssFile}" /> " />
If you're on Facelets instead of JSP, then you can also use unified EL in template text:
<link rel="stylesheet" type="text/css" href="#{bean.cssFile}" />
If you actually don't need a "print preview" tab/page, then you can also just specify the media attribute in the CSS link and let the link/button invoke window.print() during onclick instead of opening in a new tab.
<link rel="stylesheet" type="text/css" href="normal.css" media="screen, handheld, projection" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
When the page is about to be printed, the one specified by media="print" will automatically be used instead.
You can add get parameters to any JSF link by using the f:param tag.
<h:outputLink value="/somepage.xhtml" target="_blank">
<h:outputText value="Link to Some Page"/>
<f:param name="someparam" value="somevalue">
</h:outputLink>
This will render something basically like this:
Link to Some Page
You can add multiple params with more f:param fields. Alternatively, if it's static, you can just add it as part of the outputLink itself.
<h:outputLink value="/somepage.xhtml?someparam=somevalue" target="_blank">
<h:outputText value="Link to Some Page"/>
</h:outputLink>
The problem, of course, being that you cannot do this and trigger server-side events. I've yet to figure out how to do this from a POST back and get it in a new tab.