Some URL patterns lose css - java

I'm making a simple servlet app, which is supposed to produce the same output for the following URL patterns:
#WebServlet(urlPatterns={"/Start", "/Start/*", "/Startup", "/Startup/*"})
The output for the following addresses is correct:
http://localhost:4413/TestA/Startup
http://localhost:4413/TestA/Start
http://localhost:4413/TestA
However, once I try something like this:
http://localhost:4413/TestA/Startup/
or
http://localhost:4413/TestA/Startup/blablabla
The css file does not see it.
What could be wrong here?
The css links are of the form:
<link rel="StyleSheet" href="res/mc.css" type="text/css" title="cse4413" media="screen, print"/>

This depends on how you have included the CSS file. If you had included like:
<link href="css/style.css" />
Then, it won't work on directory structures. So change your code, which is similar to the above one like this:
<link href="/css/style.css" />
You need to provide the relative path to the domain, not the file. So that it always requests the right URL.

Solved the problem by setting href to
href="${pageContext.request.contextPath}/res/mc.css"
Could anyone explain how is this different from a link of the form
project/WebContent/res/mc.css?

Related

regex cut css links from html

I want to extract all css and js links from html page using regex, now I use:
([^ ()]*\.(?:css|js)\b)
that pattern, but it doesnt work perfectly, I wan to excluced symbols like '{}()}' before .css or .js path of link.
I try to use Jsoup parser but, he cant extract <link..> tags from js script inside html with code like:
if( userAgent.match( /ipad|iphone|htc|android|windows\s+phone/i ) ) {
document.write('<link rel="stylesheet" type="text/css" href="http://static.gazeta.ru/nm2012/css/new_common_css_pda54.css" />');
} else {
document.write('<link rel="stylesheet" type="text/css" href="http://static.gazeta.ru/nm2012/css/new_common_css275.css" />');
}
You can use the Javax DOM Parser since HTML is dervied from XML, or more HTML specific one like validator.nu used by Mozilla.

Dropwizard, serving two assets for the same URI

How may I serve two assets folder for the same URI in Dropwizard. Currently only the first one is being served, when using the same name for URI.
I'm registering AssetsBundle using (in my main application class):
public void initialize(Bootstrap<DummyFrontendConfiguration> bootstrap) {
bootstrap.addBundle(new AssetsBundle("/assets1", "/public", null, "assets1"));
bootstrap.addBundle(new AssetsBundle("/assets2", "/public", null, "assets2"));
bootstrap.addBundle(new ViewBundle());
}
Css file (main.css) in assets1:
h2{
color: red;
}
Css file (main2.css) in assets2:
h4{
color: green;
}
In html template head:
<link rel="stylesheet" type="text/css" href="public/stylesheets/main.css">
<link rel="stylesheet" type="text/css" href="public/stylesheets/main2.css">
In html template body:
<h2>This should be red</h2>
<h4>This should be green</h4>
Unfortunately the second css file (main2.css) couldn't be loaded during the html page rendering (404 - not found), any ideas?
The assets module isn't designed to function this way. Under the hood it's calling:
environment.servlets().addServlet(assetsName, createServlet()).addMapping(uriPath + '*');
Both servlets can't be mapped to the same path. You could fix this by switching one of the "public" mappings to be another path ("public2", for instance).
If you indeed need to keep your resources completely separate you may want to consider introducing another step in your build (via maven or ant) that merges the assets into a single directory structure for deployment.

How can I output System.currentTimeMillis() to an ADF page?

I'm using this and it doesn't work as expected. I'm trying to cache bust a css file as it changes a lot and we can't always expect users to thoroughly clear their cache.
<c:set var="buster" value="{System.currentTimeMillis()}" />
<af:resource type="css" source="/oracle/webcenter/portalapp/shared/css/maaui.css?r=${buster}"/>
Unfortunately that renders
<link rel="stylesheet" type="text/css" afrres="true" href="/myAccount/oracle/webcenter/portalapp/shared/css/maaui.css?r=%7BSystem.currentTimeMillis()%7D">
It doesn't execute the method. I tried ${} and #{} as well and neither seem to work for me.
Can anyone help me to achieve the desired result? Basically a random string that will change each time a user visits a page. I can easily do this in .NET but I am very new to Oracle ADF.
Try
<c:set var="buster" value="{myBean.time}" />
<af:resource type="css" source="/oracle/webcenter/portalapp/shared/css/maaui.css?r=#{buster}"/>
And in MyBean managed backing bean
public long getTime()
{
return System.getCurrentTimeMillis();
}

Java/Scala: understanding Play framework custom tag or helper

I've been using Play 2.0 framework for a couple of days now for a proof of concept application at my job. One of the first things I wanted to check out was the custom tag functionality, since it reminded me of HtmlHelpers in ASP.Net MVC. The thing is that I can't seem to make them work and was wondering if I'm misusing the feature or misunderstanding something.
Here's a simple example of what I want to do: I want to be able to use #script("scriptname.js") anywhere in the templates and have that subsitute the entire tags.
Here's what I got so far:
main.scala.html
#(title: String, scripts: Html = Html(""))(content: Html)
#import tags._
<!DOCTYPE html>
<html>
<head>
<!-- this is how I would like to use the helper/tag -->
#script("jquery.js")
#script("jquery-ui.js")
<!-- let views add their own scripts. this part is working OK -->
#scripts
</head>
<body>
#content
</body>
</html>
I created a subdirectory called "tags" under the app/views directory. There I created my script.scala.html tag/helper file:
#(name: String)
<script src="#routes.Assets.at("javascripts/#name")" type="text/javascript"></script>
The problem I'm having is that whenever I use #script() the output includes the #name parameter in it. For example #script("x.js") actually outputs
<script src="assets/javascripts/#name" type="text/javascript"></script>
What am I doing wrong?
For the record, I did read the documentation and search here, but neither of these links have helped me figure this out:
http://www.playframework.org/documentation/2.0.3/JavaTemplateUseCases
How to define a tag with Play 2.0?
#routes.Assets.at(...) evaluates the Scala expression routes.Assets.at(...) and substitutes the result into your output. There is no recursive evaluation that would allow you to have evaluate an expression textually to get that expression, which seems to be what you're expecting.
What you intend to do is achieved using
#routes.Assets.at("javascripts/" + name)

Struts CSS/Images per language

I have a web application deployed inJava using Struts 1 as the the MVC library.
I am required to provide different CSS/Images folders based on the selected language.
I already have WebMessageResources.properties configured with 4 different languages.
One approach I took is to define to the root path of the CSS/Images folder in the message resources.
However, I'm finding this to be somehow "dirty" and requiring changes all over the code.
For example, in one my JSP pages, I was forced get the path using JSP tags than concatenate the string in the css href.
MessageResources mres =
MessageResources.getMessageResources(Constants.RESOURCES_BUNDLE);
Locale locale = (Locale)
pageContext.getSession().getAttribute(Globals.LOCALE_KEY); String
langResources = mres.getMessage(locale, "path.resources");
....
<link rel="stylesheet" type="text/css" href="<%= langResources %>css/styles.css" />
Is there a better "out of the box" way to do this? I'm not very familiar with Struts.
struts has inbuild support for i18n. See this
http://www.mkyong.com/struts2/struts-2-i18n-or-localization-example/
http://exadel.com/tutorial/struts/5.2/strutstutorials-i18n.html

Categories

Resources