Hi,
In my Struts2 project I had an error
"No result defined for action struts2.samples.actions.ReportsAction and result success"
when I tried to use jasperreports plugin with result type="jasper" and the struts.xml action mapping is as follows,
<!DOCTYPE
struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<!-- Author: SCO03_2 -->
<struts>
<!-- Add your configuration elements here -->
<package name="default" extends="struts-default,jasperreports-default">
<default-interceptor-ref name="defaultStack"/>
<action name="persons" class="struts2.samples.actions.PersonAction">
<result name="input">index.jsp</result>
<result type="chain">reports</result>
</action>
<action name="reports" class="struts2.samples.actions.ReportsAction">
<interceptor-ref name="params"/>
<interceptor-ref name="validation"/>
<interceptor-ref name="workflow"/>
<result name="success" type="jasper">
<param name="location">${reportLocation}</param>
<param name="dataSource">${persons}</param>
<param name="format">pdf</param>
</result>
<result name="input">index.jsp</result>
</action>
</package>
</struts>
PersonsAction.java (a required part)
public
String execute() throws Exception {
try {
PersonsDao personsDao=new PersonsDao();
//calling helper class method to create a Person record on the data store
personsDao.create(firstname, lastname, age,sex,address,document,documentFileName);
return "success";
} catch (Exception ex) {
addActionError(ex.getMessage());
return "input";
}
}
ReportsAction.java
public String execute(){
try{
PersonsDao personDao=new PersonsDao();
persons=(List<Person>)personDao.list();
setReportLocation(new PersonsReport().createReport(request,"reports/Persons.jrxml","reports/Persons.jasper"));
return "success";
}catch(Exception ex){
ex.printStackTrace();
addActionError(ex.getMessage());
return "input";
}
}
In Actions,(PersonsAction.java and ReportsAction.java) functionality was perfect except the result view as jasper.File was properly uploaded in the desired location. I need the solution for this. I require your help.
Best Regards,
Ramesh K