struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dave Newton <davelnew...@gmail.com>
Subject Re: result type Jasper [Struts 2]
Date Wed, 17 Nov 2010 04:25:05 GMT
(a) Make sure the HTML is rendering the way you expect, and (b)
ideally run the home page through an action. Also try setting the
namespace explicitly in the link tag; if you're not in an action it
might not know where it's mapping from/to.

Dave

On Tue, Nov 16, 2010 at 11:20 PM, @rju <nagarjunabattula@gmail.com> wrote:
>
> please help me am not getting report generation.. my code is as follows
> and am uploading the project and out put images please help me regarding
> this http://old.nabble.com/file/p30235277/JReport.rar JReport.rar
> my out puts
>
> http://old.nabble.com/file/p30235277/Output1.jpg
> http://old.nabble.com/file/p30235277/Output2.jpg
> http://old.nabble.com/file/p30235277/AfterAddingJasperPlugin.jpg
> in these images you can see the directory structure i ve followed and jar
> files i have added
>  -----struts.xml
> <?xml version="1.0" encoding="UTF-8" ?>
> <!DOCTYPE struts PUBLIC
>    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
>    "http://struts.apache.org/dtds/struts-2.0.dtd">
> <struts>
>        <package name="default" namespace="/" extends="jasperreports-default">
>                <result-types>
>           <result-type name="jasper"
> class="org.apache.struts2.views.jasperreports.JasperReportsResult" />
>   </result-types>
>                <action name="report" class="com.action.JasperAction">
>                <result name="success" type="jasper">
>                        /jasper/Report.jasper
>                        myList
>                        PDF
>                </result>
>                </action>
>        </package>
> </struts>
>> -------------------------------------------------------------
>> -----web.xml--------
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"
>  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
>  <filter>
>  <filter-name>struts2</filter-name>
>
> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
>  </filter>
>  <filter-mapping>
>  <filter-name>struts2</filter-name>
>  <url-pattern>/*</url-pattern>
>  </filter-mapping>
>  <welcome-file-list>
>  <welcome-file>index.jsp</welcome-file>
>  </welcome-file-list>
> </web-app>
>> --------------------------------------------------------------
>> --------index.jsp------------
>>
>> <%@ page language="java" import="java.util.*" pageEncoding="ISO-8859-1"%>
>> <%@ taglib uri="/struts-tags" prefix="s" %>
>><body>
> <s:form action = "report">
>        <s:submit value="Report"/>
> </s:form>
>  </body>
>> --------------------------------------------------------
>> -----person.java-----------
>> package com;
>>
>> public class Person {
>>
>>    private Long id;
>>
>>    private String name;
>>
>>    private String lastName;
>>
>>    public Person() {
>>    }
>>
>>    public Person(String name, String lastName) {
>>        this.name = name;
>>        this.lastName = lastName;
>>    }
>>
>>    public Person(Long id, String name, String lastName) {
>>        this.id = id;
>>        this.name = name;
>>        this.lastName = lastName;
>>    }
>>
>>    public Long getId() {
>>        return id;
>>    }
>>
>>    public void setId(Long id) {
>>        this.id = id;
>>    }
>>
>>    public String getLastName() {
>>        return lastName;
>>    }
>>
>>    public void setLastName(String lastName) {
>>        this.lastName = lastName;
>>    }
>>
>>    public String getName() {
>>        return name;
>>    }
>>
>>    public void setName(String name) {
>>        this.name = name;
>>    }
>>
>> }
>> ------------------------------------
>> ---------JasperAction.java----------
>> package com.action;
>>
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> import javax.servlet.ServletContext;
>>
>> import org.apache.struts2.ServletActionContext;
>> import com.opensymphony.xwork2.ActionSupport;
>>
>>
>> import net.sf.jasperreports.engine.JasperCompileManager;
>> import com.Person;
>>
>>
>>
>> public class JasperAction extends ActionSupport {
>>
>>    /**
>>         *
>>         */
>>
>>        private static final long serialVersionUID = 1L;
>>        /** List to use as our JasperReports dataSource. */
>>    private List myList;
>>
>>
>>        public String execute() throws Exception {
>>
>>        // Create some imaginary persons.
>>        Person p1 = new Person(new Long(1), "Patrick", "Lightbuddie");
>>        Person p2 = new Person(new Long(2), "Jason", "Carrora");
>>        Person p3 = new Person(new Long(3), "Alexandru", "Papesco");
>>        Person p4 = new Person(new Long(4), "Jay", "Boss");
>>
>>        // Store people in our dataSource list (normally they would come
>> from a database).
>>        myList = new ArrayList();
>>        myList.add(p1);
>>        myList.add(p2);
>>        myList.add(p3);
>>        myList.add(p4);
>>
>>        // Normally we would provide a pre-compiled .jrxml file
>>        // or check to make sure we don't compile on every request.
>>        try {
>>                ServletContext context = null ;
>>
>>                context = ServletActionContext.getServletContext();
>>
>>
>> JasperCompileManager.compileReportToFile(context.getRealPath("/jasper/Report.jrxml"),context.getRealPath("/jasper/Report.jasper"));
>>
>>
>>        } catch (Exception e) {
>>            e.printStackTrace();
>>            return ERROR;
>>        }
>>
>>        return SUCCESS;
>>    }
>>
>>    public List getMyList() {
>>        return myList;
>>    }
>>
>> }
>> -------------------------------
>> This is the thing
>> and i have placed my Report.jrxml and Report.jasper in the directory
>> called
>> "jasper".
>> and i am trying to place this directory in every place i.e. once in
>> "classes" folder, root folder, web-inf folder i am trying all and project
>> is
>> running Report button is coming but after pressing the Report Button am
>> not
>> getting out put.. You can see the ouputs in my attachmens. namely
>> Output1,Output2. In that you can find the directory structure i have
>> flollowed.... Please Please help me...
> --
> View this message in context: http://old.nabble.com/result-type-Jasper--Struts-2--tp11004749p30235277.html
> Sent from the Struts - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message