Play Framework 2.2.0 seems to incorrectly display html content that comes from an Html object inside a layout. Given the following templates:
main.scala.html:
#(title : String)(content: Html)
Price 10€
#content
index.scala.html:
#main("Index") {
Price: 20€
}
The result of rendering index.scala.html is:
Price 10€
Price 20�
Something happens to the content displayed inside the layout, but not to the content on the outside. Am I missing something? Thanks!
Turns out Eclipse was setting different encodings for different files and it was breaking the characters.
A similar post about this problem is here:
Wrong Charset Encoding with Play Framework 2.1
Related
I am using thymeleaf as my template engin to map XHTML to HTML and flying saucer to generate a pdf file afterwards.
Now i failed to display my static images located at /src/main/resources/ inside y generated pdf file. The file itsself will be displayed fine only images disapear.
Even other locations like /src/main/resources/static or /src/main/resources/public didnt help.
My HTML / XHTML looks like:
<img src="images/logo_black.png"></img>
<img src="/images/logo_black.png"></img>
<img alt="mastercard" th:src="#{classpath:static/images/logo_black.png}" />
<div data-src="images/logo_black.png"></div>
<div data-src="/images/logo_black.png"></div>
<div data-src="#{classpath:static/images/logo_black.png}"></div>
none of them is working properly.
The Images itself are visible by localhost:8048/logo_black.png
I dont want to refer my images with a full url (http://...)
You can include resources from any URL (from the Internet or from your file system). Either way, there are several steps involved:
When generating the HTML from the Thymeleaf template, you can use
#{/some/url} to resolve a path relative to your Web context (assuming you have a Web context), or
#{classpath:/some/url} with will just leave the URL as classpath:/some/url, or
simply a string value constant or a value from a variable (${var}), doesn't matter if it's an absolute URL https://some/url or relative, Thymleaf will leave them unchanged in the resulting HTML.
Before you pass the HTML to Flying Saucer, make sure the URLs are correct. Then Flying Saucer will process all URLs with a UserAgentCallback, by default ITextUserAgent.
The relevant methods in UserAgentCallBack are resolveURI and setBaseURL.
There is some weird logic going on in the default resolveURI method of ITextUserAgent (inherited from NaiveUserAgent). If the baseURL is null, it will try to set it, so it's best to always set it yourself. I had better results with overriding the resolveURI, the following is enough to keep absolute URLs and resolve relative URLs relative to the baseURL:
#Override
public String resolveURI(String uri) {
if (URI(uri).isAbsolute())
return uri;
else
return Paths.get(getBaseURL(), uri).toUri().toString();
}
Finally, in order to resolve the classpath: protocol, you need to define an URLStreamHandler unless there is already one defined (for example, the embedded Tomcat of Spring Boot already does supports this).
You can render image with the help of base 64 .You just convert your image on base 64 and it will show on your web page as well as mobile view.The tags are:
<img th:src="#{data:image/png ;base64,your base 64}"/>
I would like to add a functionality that shows a pdf on a certain page. I have the pdf as a File in my code. So I cannot get it from my webserver.
I also have the pagenumber.
I've seen that the adobe plugin accepts #page=1 but I don't know how to use this in a web based application.
I also found some tutorials wich display it in an Iframe. But these use :
org.apache.wicket.markup.html.DynamicWebResource
And this doesn't exist anymore.
I found it's replaced by
org.apache.wicket.request.resource.ByteArrayResource
Are there any tutorials/tips on how to do this (Wicket 1.5 or higher)?.
You can use ResourceLink with ByteArrayResource, or you can use any link/button and in its onClick/onSubmit() you can do:
getRequestCycle().scheduleRequestHandlerAfterCurrent(
new ResourceRequestHandler(new ByteArrayResource(...)))
In both cases you may need to set the content-disposition header by overriding org.apache.wicket.request.resource.ByteArrayResource#configureResponse() and calling ResourceResponse#setContentDisposition(INLINE) for it.
When you modify the data from you're object tag pass a pagenumber. This passes the page to the adobe plugin and automatically sets the page. (I have only tested this in chrome 21 and IE9)
<object wicket:id="myFile" data="" border="1" width="100%" height="600px"></object>
WebMarkupContainer wmc = new WebMarkupContainer("myFile");
wmc.add(new AttributeModifier("data", (String) urlFor(rr, null)+"#page="+ pageNmbr));
add(wmc);
Here's the problem:
Take a look at: http://postimage.org/image/zclhvutfl/
The question is how to get rid of appending the urls to links?? They are appended to every link in application. I.e. there should be only "Index" and "Time" word in the links, but there is also appended path to them. In Firebug I can see that everything is OK, but the links render as you see on above screenshot.
Im using Apache MyFaces and PrimeFaces on Tomcat 7. I already tried to remove PROJECT_STAGE=development from web.xml, but that was not the issue.
SOLVED: it was just z blueprint css style for <a>
a:link:after, a:visited:after {
content: " (" attr(href) ")";
font-size: 90%;
}
sounds funny, but I'm working with blueprint for one year now, but versions I had eariler didn't have this feature ;-)
Hey everyone I am making my first applet for java today. I have been using a subdomain at a server and I don't know what to do because I am getting this really weird error.
I have my jar in the server and everything but every time I try to load the Applet this happens.
java.lang.ClassFormatError: Incompatible magic value 218774561 in class file Evolution/EvolutionApplet
Upon research it appears that an incompatible magic value means that something has been corrupted in the .jar
Here is the website http://dementedgames.site88.net/Main.html
the jars name is Evolution if you need the html code it is at the website.
Edit: The applet should be launched from Evolution.EvolutionApplet not Evolution.Evolution
The magic value of a valid Java class is 0xCAFEBABE, which is the hex value of 3405691582. This is represented by the first 4 bytes of the file. But you're getting 218774561 which in turn stands for the ASCII characters CR, LF, < and ! (the CRLF is a newline). To see it yourself, run this piece of code:
int magic = 218774561;
ByteBuffer b = ByteBuffer.allocate(4);
b.putInt(magic);
System.out.println(new String(b.array()));
This in combination with the applet being served by a website suggests that it's the start of a <!DOCTYPE> which in turn suggests that it's a HTML document.
So, the request to Evolution.jar has apparently actually returned a HTML document. You should be able to see it yourself when you change the current request URI in browser address bar to point to applet's URL (e.g. change /page.html in end of URL to /Evolution.jar). Then you'll see what the browser actually retrieved when it tried to download the applet. Perhaps it's a simple HTTP 404 error document.
To fix it, just make sure that the URL in the archive attribute is correct. It's relative to the current request URL as you see in browser address bar.
The original problem seems fixed now. I could download the Jar from http://dementedgames.site88.net/Evolution.jar
Update
It seems the Evolution.Evolution class is not an applet! Running it from the command line using:
java -jar Evolution.jar
Produces a frame (with a very 'retro' look)! As such, forget this applet nonsense, and launch the frame from a link using Java Web Start.
Old Answer
OTOH it now throws a ClassNotFoundException that (after inspecting the Jar) makes me think it should be:
<html>
<head>
<title>Evolution</title>
</head>
<body bgcolor="#000000" text="#906060">
<center>
<applet code="Evolution.Evolution" archive="Evolution.jar" width="800" height="600">
</applet>
</center>
</body>
</html>
There are two changes to the code attribute worth noting.
The .class extension was removed. A minor matter, adding it is tolerated, but not correct.
The Applet removed from the class name.
BalusC above has explained it really well. In addition to that you can check this link
Thread: Incompatible magic value 218774561 error in applet
It seems that the codebase and/or the code attribute of ur applet tag need to pointed properly.
How can I open an HTML page and show it in a text area? (If I choose the HTML file with the JFileChooser, how can I open that page and show it in the text area?)
URL url = new URL(String s);
JEditorPane pane = JEditorPane(url);
But how can I find the link of the HTML file for inserting as s, here!?
A TextArea is for displaying/editing text, not for showing formatted HTML.
JEditorPane supports HTML markup, but only a rather limited subset.
For full HTML support, you're going to need third-party components. Look at the answers to this question for links.
Format the HTML with a <pre> tag
I guess you can use any properly formatted URL a browser would use e.g.
http://stackoverflow.com/questions/1239454/how-can-i-open-an-html-page-and-show-it-in-a-text-area
But then again Java is very keen on security and you might not be allowed to use certain URLs in your environment.
And like Michael Borgwardt said - the JEditorPane's support of HTML is very limited and some tags (i think <div> is one of them) as well as JavaScript are not supported.
For implementation of a simple browser have a look at this
JEditorPane Tutorial