Unable to access jpg in jsp - java

There are two image files in my webcontent/images folder the_logo.jpg and logo.png
I am able to access the .png file
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
but unable to access the .jpg file
<img alt="Powerpay" src="./images/the_logo.jpg" width="250" height="50" />
How should I solve this?
Feel free to ask if any other information is needed.
NOTE : I am using Apache tomcat.

use
<img alt="Powerpay1" src="../images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="../images/the_logo.jpg" width="250" height="50" />
This code will take the cursor to the previous folder.
If you have two nested folder, use ../../ or three nested folders, use ../../../and so on to go to the root of the directory and browse respectly.
instead of
<img alt="Powerpay1" src="./images/logo.png" width="250" height="50" />
<img alt="Powerpay1" src="./images/the_logo.jpg" width="250" height="50" />
One more best way to doing it by using scriptlets
Ex:
<%
String base = request.getContextPath() + "/";
if (base == null || base.isEmpty()) {
base = "/";
}
%>
<img alt="Powerpay1" src="<%=base%>images/logo.png" width="250" height="50" />

Apache configuration can allow specific suffixes. see mod_suffix
File in linux should be in a path as /etc/httpd/conf/httpd.conf
Try changing your files match patterns to add jpg:
<FilesMatch "\.(png|**jpg**|gif|css|php|html|js)$">
allow from all
</FilesMatch>

Related

JSP markup inside <tiles:put> or a or an alternative

I've inherited an old application that is using Struts 1.2 Tiles 1. For various annoying reasons I can't upgrade.
I'm not very familiar with Struts, or specifically Tiles in general and I'm trying to do something that makes sense in my head but I can't seem to make work in practice. Here's an example of what I'm trying to accomplish:
<tiles-definition>
<definition name="content-with-sidebar" path="/content_with_sidebar.jsp">
<put name="top" value="" type="string" />
<put name="sidebar" value="/tiles/sidebar.jsp" />
<put name="main" value="" type="string" />
<put name="bottom" value="" type="string" />
</definition
</tiles-definition>
content_with_sidebar.jsp
...
<tiles:insert attribute="top" flush="false" />
<div id="content">
<aside>
<tiles:insert attribute="sidebar" flush="false" />
</aside>
<div id="main">
<tiles:insert attribute="main" flush="false" />
</diV>
</div>
<tiles:insert attribute="top" flush="false" />
...
actual_page.jsp
<tiles:insert definition="content-with-sidebar" flush="false">
<tiles:put name="top" type="string">
<div>Maybe this page has something on the top that isn't the page header</div>
</tiles:put>
<!-- use the default sidebar -->
<tiles:put name="main">
<strong>Current Location:</strong>
<address><h:outputText value="#{locationDesc} #{zipCode}" /></address>
<!-- Some more dynamic jsp markup -->
</tiles:put>
<!-- This one doesn't have anything extra on the bottom -->
</tiles:insert>
This almost works but the dynamic bits get rendered above and outside the <tiles:insert> and the plain strings go where they should. I understand now, after much searching, that <tiles:put> in this, er, context, is expecting a plain ole string.
Is there a pattern to accomplish what I want with dynamic context?
As it stands I'm having to create another jsp file to be referenced by the <tiles:put> tag. i.e.
<tiles:put name="main" value="/actual_page_body.jsp" />
I'd rather not have to create an additional file when one would do. Any advice would be helpful.
With tiles, when the definition is rendered (content-with-sidebar in your code), the jsp corresponding to the 'path' attribute (/content_with_sidebar.jsp) will be invoked. All other jsps have to be manually invoked using a <tiles:insert>. What tiles provides you is a way to configurationally invoke them as definition attributes.

Which swing tool is used?

I have a java program installed on my computer that creates Forms and can later print it. I want to do something similar with my program! In the source folders of this program, I found folders for the specific forms. Each folder containes a image for e.g named Payment.png and a xml file is structured like this:
<?xml version="1.0" encoding="windows-1250" standalone="no"?>
<form xmlns:xinclude="http://www.w3.org/2001/XInclude" blankodruck="true" filename="Payment.png" saveAndPrintButtonEnabled="true" scale="1.0" title="Payment" window_height="725" window_width="860" paper="A5" orientation="landscape">
<printscale sx="0.432" sy="0.434"/>
<printoffset x="0" y="13"/>
<model class="de.hans.client.app.form.payment.PaymentModel" />
<printform filename="Payment.png" pngscaleX="1" pngscaleY="1"/>
<offset x="-20" y="15" scaleX="0.72" scaleY="0.7" printOffsetX="4" printOffsetY="3" printScaleX="2.34" printScaleY="2.33">
<xinclude:include href="../Header.xml"/>
</offset>
<checkbox height="33" name="Paydaten_ChB" width="35" x="862" y="74" printOffsetX="0" printOffsetY="0"/>
<checkbox columns="90" height="35" ...
<textfield columns="1" height="36" name="quartal" width="35" x="1235" y="72" printOffsetX="0" printOffsetY="0"/>
<radiobutton group="Gender" height="36" name="User_gender" tooltip="men" width="33" x="1253" y="130" printOffsetX="0" printOffsetY="0"/>
It has even a barcode-field:
<barcode length="886" type="3" px="430" py="180" pages="1">
<invisible name="date"/>
<invisible name="titel"/>
Can somebody guess how this printable swings are created in the program? Thanks

Batik - put SVG on top of image

I have an image file (jpg, etc.) and some svg drawings (svg tag copied from the site, as Java String). The svg drawing is of the same resolution as the image file. I want to put svg drawings on top of the image and save it as one file. My approach, of which I'm not proud of, but works, is to:
use Batik's JPEGTranscoder to transcode svg into image with this svg drawings and white background, save this image
put the image with svg drawings on top of my image file by perfoming low level operations on each pixel
I would like to be able to put the svg drawings on top of my image in one step.
Using an SVG pattern would solve your problem.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="200" height="200">
<defs>
<pattern id="image" x="0" y="0" patternUnits="userSpaceOnUse" height="200" width="200">
<image x="0" y="0" width="200" height="200"
xlink:href="http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png"/>
</pattern>
</defs>
<rect width="200" height="200" fill="url(#image)"/>
<circle cx="100" cy="100" r="50"/>
</svg>
Fiddle available here.
I pulled the SVG above through the batik rasterizer, and it was correctly rasterized.
Update
As noted in the comments, you could just as well include the image directly in your SVG, without the use of a pattern.
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
width="200" height="200">
<image x="0" y="0" width="200" height="200"
xlink:href="http://cdn.sstatic.net/stackexchange/img/logos/so/so-logo.png"/>
<circle cx="100" cy="100" r="50"/>
</svg>
Fiddle available here.

How can I read system properties in a tagx/jspx?

I am defining a tagx file called "version.tagx". The responsibility of this tag is to emit an anchor tag whose display text is the version number of the application. Currently, the definition of the file looks like this:
<jsp:root xmlns:c="http://java.sun.com/jsp/jstl/core" xmlns:fn="http://java.sun.com/jsp/jstl/functions" xmlns:spring="http://www.springframework.org/tags" xmlns:jsp="http://java.sun.com/JSP/Page" version="2.0">
<jsp:output omit-xml-declaration="yes" />
<jsp:directive.attribute name="render" type="java.lang.Boolean" required="false" rtexprvalue="true" description="Indicate if the contents of this tag and all enclosed tags should be rendered (default 'true')" />
<c:if test="${empty render or render}">
<spring:message code="global_version" />
<spring:url var="changelog" value="/resources/changelog.txt" />
<c:out value=": " />
${application_version}
</c:if>
</jsp:root>
My application is a Spring MVC application running in a Tomcat 7x container. I have the following line in my applicationContext.xml
<context:property-placeholder location="classpath*:META-INF/spring/*_${spring.profiles.active}.properties,classpath:app-info.properties"/>
I have confirmed through following the DEBUG log message the app-info.properties file is discovered by Spring and (presumably) the property values within that file have been loaded into my runtime.
Here is the log message
2012-05-09 23:45:24,237 [main] INFO org.springframework.context.support.PropertySourcesPlaceholderConfigurer - Loading properties file from class path resource [app-info.properties]
2012-05-09 23:45:24,237 [main] DEBUG org.springframework.core.env.MutablePropertySources - Adding [localProperties] PropertySource with lowest search precedence
And here are the contents of my app-info.properties file:
application_version=1.0
application_buildTime=05-04-2012 00:00:00
application_builtBy=me
application_buildNumber=55
What I want is for my tagx to emit
Version: 1.0
And currently what I get is:
Version:
Does anyone know of a way to accomplish this? Should I be trying a completely different approach that forgoes properties files all togher?
In webmvc-config.xml add util:properties where /WEB-INF/spring/application.properties is the path to the properties file:
<util:properties id="applicationProps" location="/WEB-INF/spring/application.properties"/>
Then, simply add this before your anchor tag:
<spring:eval expression="#applicationProps['application_builtBy']" var="application_builtBy"/>
<spring:eval expression="#applicationProps['application_buildTime']" var="application_buildTime"/>
<spring:eval expression="#applicationProps['application_version']" var="application_version"/>
Hope it helps.
What you can also do that doesn't tie you to looking up properties in a single property placeholder, or if you are using java config and just instantiating a PropertySourcesPlaceholderConfigurer is use the environment object:
<spring:eval expression="#environment.getProperty('application_builtBy')" />

Output key to localized message returning 0

I'm trying to output a key to a localized message in a jsp template in the following way:
<c:set var="logo-tooltip-title">
<fmt:message key="logo.tooltip.title"/>
</c:set>
<c:out value="${logo-tooltip-title}"/>
With the following in my messages.properties file:
logo.tooltip.title=Test
Does anyone know what I'm doing wrong here? Why does it return 0 instead of Test?
My goal is to output that message as title of the following link:
<a class="logo" href="/site/" title="${logo-tooltip-title}">
<img src="<hst:link path="/img/logo.png"/>" alt="logo" class="headlogo" width="80" height="100" />
</a>
Any thoughts on the best approach to do this?
Thanks!
EDIT:
yes I have set the context param in web.xml:
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>messages</param-value>
</context-param>
resource
Update:
This seems to work:
<fmt:message key="logo.tooltip.title" var="tooltip"/>
<c:out value="${tooltip}"/>
I don't think your problem is specific to HippoCMS.
I tried your syntax and I think you're missing a bundle declaration. If I add an org/ecausarano/Example.properties file to the war resources and:
<fmt:setBundle basename="org.ecausarano.Example" />
<c:set var="message">
<fmt:message key="message.message" />
</c:set>
<c:out value="${message}" />
it works for me.
JSTL tries to do math for "logo - tooltip - title" which results in 0. You've already found out that replacing the - by . solved the issue.

Categories

Resources