top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

accessing an external file in the struts.xml

0 votes
1,016 views

Is it possible to access a file that is located in the local drive or server side folder from struts.xml? as follow:

C:/Folder/jasperReport.jasper

or

%{filename} 

where the filename is avariable in the action class with the file location is hardcoded as String filename = "C:/Folder/jasperReport.jasper";

My struts2 application is deployed on JBoss as 6, it seems ServletRequestAware is unable to access the folder within war file while working with JBoss. It is working fine with tomcat. I am thinking about accessing files in the server size instead.

posted Jul 2, 2013 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Much of the answer depends on what your application server is. In any case, I don't think this is a good practice. IMO you should include the file with your webapp and find a way to access to it.

answer Jul 2, 2013 by anonymous
Thanks for responding to my question. However, JBoss server does not explode the war deployed to it. Unlike tomcat, it does explode the war file, and this is why it is easy to access files within a war file.

Here's is my code

private HttpServletRequest servletRequest;
@Override
    public void setServletRequest(HttpServletRequest httpServletRequest) {
        // TODO Auto-generated method stub
        this.servletRequest = httpServletRequest;
    }
String filePath = servletRequest.getSession().getServletContext().getRealPath("/MyApp/web/jasper/jasperReport.jasper");
However, I am getting the following path when debugging the above code:

C:jboss-6.0.0.Finalserverdefaulttmpvfsautomounta5bfada4df82fa0eMyApp.war-ec6d753dd0506906webjasperjasperReport.jasper.

The JasperReport.jar is located at the MyApp/web/jasper/ folder.
You have at least one extra layer in your file path, normally you'd keep files like this under WEB-INF, and start the file path from there.
I moved the file placed under /WEB-INF directory, but the action class still cannot located the path to the file.
Similar Questions
0 votes

I was able to generate a PDF file using struts2-jasperreports-plugin using java.util.List as datasource. However, I am not able to do the same with the java.util.Map datasource.

My question is anybody knows how to use java.util.Map datasource in the struts2-jasperreports-plugin?

+1 vote

Facing some issue, while we use wildfly-deploy maven plugin to deploy strut2 application to wildfly aka jboss 7, struts2 is unable to read package.properties file packaged inside .war. If i deploy from an IDE or manually then there is no issue.

The only difference is wildfly-deploy plugin is deploying application war inside {WILDFLY_HOME}/standalone/data/ folder where as manual or IDE will deploy it under {WILDFLY_HOME}/standalone/deployments/ folder.

In essence struts2 unable to read package.properties file if deployed under certain location.

Any thoughts, application is working perfectly except label's are not coming only label key is coming in screens.

+2 votes

I have a couple of old struts 2 apps that are using 2.2.1. I want to upgrade them to 2.3. What is the minimal set of jar files I need in WEB-INF/lib?

I currently have:
commons-beanutils-1.7.jar
commons-collections-2.1.jar
commons-digester-1.7.jar
commons-fileupload-1.2.1.jar
commons-io-1.4.jar
commons-javaflow-20060411.jar
commons-lang-2.5.jar
commons-logging-1.0.4.jar
freemarker-2.3.16.jar
ibatis-2.3.2.715.jar
itext-1.3.1.jar
jasperreports-2.0.5.jar
javamail.jar
javassist-3.8.0.GA.jar
jdt-compiler-3.1.1.jar
jstl.jar
jxl-2.6.jar
log4j-1.2.14.jar
ognl-3.0.jar
poi-3.0.1-FINAL-20070705.jar
spring.jar
standard.jar
struts2-core-2.2.1.jar
struts2-jasperreports-plugin-2.0.11.1.jar
urlrewrite-3.2.0.jar
xalan.jar
xercesImpl.jar
xwork-core-2.2.1.jar

+1 vote

In struts2 , defined an interceptor, it triggered by Action, my question is

"inside the interceptor class, what is the function call that can tell caller's name, because that interceptor could be triggered by different Action, we need to log the caller's name, but how?"

...