• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Using the JSP parameters to fill detail in a word document

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi all...
I have this JSP file which takes certain information from the user...for example :
User name
Order Amount
Ordered Items
and so on ...
now i have a word document which consists of rows and coloums for username,order amount , and ordered items ...
how would i pass the parameters from this JSP file to the word document .... and then send this word document as an attachment through the mail ......!!!???
please ... any one with working ideas.....please help..!!
...
thanxs.....
 
Ranch Hand
Posts: 160
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello ,
Well if you want the data to be sent to word file this show there should be database connectivity as you can do this in excel sheet , amke a table in excel and then make a connection and send the data to this excel sheet or vice or versa.
Thanks
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a number of ways you could try this:
- to manipulate the Word doc. directly you'd need a Java-COM bridge (such as JIntegra). However, all these bridging api's cost quite a bit of money (though JIntegra is quite good).
- alternatively, you could try to access Word with JNI - which is a big job.
- or write the word integration in a MS native language/script (WSH using CDO would do), export your data to the file systems and call the MS script using java's Runtime class. Though this is asking for errors.
Which ever you consider trying to do this is non-trivial, so I'd recommend trying a different format for you mail message. HTML would do fine, since it has formatted tables. You could either send the message as HTML or add the table as a seperate Part of a Mime message (see Java Mail Service API if you don't understand what this means).
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In addition to the method suggested, I think the most direct way is to study the document format of MS Word, say you put a template Word document, and mark some special *characters* in Word, by knowing that what format are them be in the raw Word file.
Then, you can use FileInputStream to read the file, and detect all special *characters* and replace them with the form values accordingly.
Of course, this is also a big learning. And it maybe very painful. I did similar thing in the past, while PDF documents, and I think it may not be that worst unless there is a strong reason.
Nick.
 
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The last method is probably the most flexible too. By making the parser a generic interface a different document type can be (relatively) easily plugged in at a later date if and when needed.
It also makes it possible to run the application on a machine without MS Word installed, which is often paramount for serverside applications as those usually run on dedicated machines many of which will be running some form of Unix.
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
my god.... every thing sounds so complicated...... can plz some guide me in the coding part....or some site that gives a tutorial for writing codes to generate word or pdf documents and then send parameters to these documents ...plz.....!!!
i need help for coding...!!!plz help..
thanxs....for all the replies...!
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i have this code .. that makes the PDF and then writes into the PDF.... but how would i pass values to this code from JSP..........??? please any one..help..!
If i use this code directly into the JSP it doesn't work .... if i make a seprate method ... to create the PDF .. then how would i call it in the main ... please any help would be appreciated..!!!
package test1;
import java.io.*;
import java.awt.Color;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;
public class Chap0101 {
public static void main(String[] args) {
System.out.println("Chapter 1 example 1: Hello World");
Document document = new Document();
try {

PdfWriter.getInstance(document, new FileOutputStream("create.pdf"));
document.open();
document.add(new Paragraph("Hello World"));
}
catch(DocumentException de) {
System.err.println(de.getMessage());
}
catch(IOException ioe) {
System.err.println(ioe.getMessage());
}
document.close();
}
}
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

place this in a class you can call from your JSP.
From the JSP (or anywhere) call createDocument("hello.pdf", "Hello World");
Mind that you will need to provide a path to write to!
You can get the path of the webapp using getServletContext().getRealPath("/WEB-INF") which would return the path on disk to your WEB-INF directory.
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i applied the code that you had posted ... but if the Document is not prefixed with the word public then i cannot access the method in the JSP .. so i have added the word public to the method ... now i can acceess the method in JSP .... but when i try to execute the program .. .i get this error ...

java.lang.IllegalAccessError: try to access method atmmachine.pp.createDocument(Ljava/lang/String;Ljava/lang/String Lcom/lowagie/text/Document; from class org.apache.jsp.Detail_0005fInterface$jsp
at org.apache.jsp.Detail_0005fInterface$jsp._jspService(Detail_0005fInterface$jsp.java:113)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:107)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:202)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:382)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:474)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2343)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1012)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1107)
at java.lang.Thread.run(Thread.java:484)

my class file code is as follows
package atmmachine;
import java.io.FileOutputStream;
import java.io.IOException;
import com.lowagie.text.*;
import com.lowagie.text.pdf.PdfWriter;

public class pp {
public Document createDocument(String filename, String helloString)
{
Document document = new Document();
try
{
PdfWriter.getInstance(document, new FileOutputStream(filename));
document.open();
document.add(new Paragraph(helloString));
}
catch(DocumentException de)
{
System.err.println(de.getMessage());
}
catch(IOException ioe)
{
System.err.println(ioe.getMessage());
}
document.close();
return document;
}
}
and my JSP code is
<%@ page contentType="text/html; charset=windows-1252" language="java" import="java.sql.*,java.io.*,java.util.*,java.sql.*,java.text.*,java.util.Date,java.*,com.lowagie.text.*,com.lowagie.text.pdf.PdfWriter" %>
<%@ page session = "true"%>
<jsp:useBean id="text123" scope="session" class="atmmachine.pp" />
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns ="urn:schemas-microsoft-com ffice ffice" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Language" content="en-us">
<meta name="GENERATOR" content="Microsoft FrontPage 5.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>ADD DETAILS - INTERFACE</title>
</head>
<body>
<%
Class.forName("com.mysql.jdbc.Driver");
Connection conn=DriverManager.getConnection("jdbc:mysql://128.1.2.3:3306/itsupport","cbqnet","cbqnet");
atmmachine.pp create = new atmmachine.pp();
String filename = "test123.pdf";
String helloString = "created the acrobat document";
create.createDocument(filename, helloString);
%>
</body>
</html>
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Why you these 2 statements?
You have already defined a JavaBean instance by:

The instance name of the JavaBean is text123.
So, you can simply replace your JSP as:

In addition, you also need to import the package atmmachine.pp in the page directive.
See whether this work.
Nick.
 
Rekha Pande
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
THANK YOU SOOOOOOOOOOOOOOOOOOOOOOOOOOOO MUCH ...IT WORKED..!
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad we could help. Good luck with your project.
 
Nicholas Cheung
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Rekha,
That's great for you.
Best wishes to your project.
Nick.
 
Remember to always leap before you look. But always take the time to smell the tiny ads:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic