Printing recipt using jsp

hi everybody, Happy easter
i want to print a recipt using jsp.
i tried using JavaScript but it is printing a full page.
plz help me.
thanks in advance

Printing through the web is very limited. The only way to do it is through window.print(). There are a few ways to control the printed output however:
- "printer friendly" link. When the user clicks this link you create a page with only the information that needs to be printed.
- using CSS you can control the printer output.
http://www.meyerweb.com/eric/articles/webrev/200001.html

Similar Messages

  • How to write printing function using JSP?

    dear all,
    i want to add a printing function in my project but i do not know how to do it? could anyone teach me how to do it?
    thanks
    eric

    salut eric,
    you can do it this way :
    1 - create a html link in your code to this javascript
    function : (I am using Struts, but you can write it in
    pure html
    <html:link href="#bodyStart"
    onclick="openWindowForPrinting()"
    titleKey="msg.status.print">      <bean:message
    key='app.print' />
    <script language="JavaScript">
    <!--
    window.open = SymRealWinOpen;
    //-->
    </script>
    </html:link>
    >
    >
    2 - here is the javascript function : it open a window
    with the "print.jsp" page.
    function openWindowForPrinting(){
    window.open('/your_project/pages/common/print.jsp','',
    'left=150, top=150 , status=no, directories=no,
    toolbar=no, menubar=yes, location=no, scrollbars=yes,
    resizable=yes, dependant=yes');
    3 : here is the print.jsp page : You have only to
    create a session variable called
    "currentBodyRelativeLocation", which content the
    relative URL to the page you want to print (for
    example, the boby of the current page).
    <%@ taglib uri='/WEB-INF/tlds/perso.tld'
    prefix='perso' %>
    <html>
    <head>
    <perso:csslink page='${cssRelativeLocation}' />
    </head>
    <body onload="var SymTmpWinOpen = window.open; window.open = SymWinOpen; printPage();; window.open = SymTmpWinOpen;">
    <body>
    <jsp:include page="${currentBodyRelativeLocation}"/>
    </body>
    <script language="JavaScript">
    <!--
    window.open = SymRealWinOpen;
    //-->
    </script>
    </html>
    <script language='javascript'>
    function printPage(){
    window.print();
    window.close();
    </script>
    hai,
    i'm not very understand how is your code work. when i write html code, do i need to mind about this code: "msg.status.print" ? what is this code mean?
    i have too much question on this thing. would you mind to be further explain to me? or is it any reference for me to refer? i'm really new to write printing function on JSP.
    i never write this function before. i'm feel so lost.....:(
    thanks again
    eric

  • How to print data using JSP

    I have a jsp/html page. Which has some data and I want to print the data of that page using jsp.Means I want to display the page and an option which will ask whether user wants to print the page or not. And if the user select print option then it will print the displayed page using printer.
    Please help me how I can proceed.
    Regards,
    Sundeep Mohanty

    Yes
    window.print will print the current displayed page
    also...it wuill not print directly...but will open the print dialog box of ur default printer i guess.

  • Problem in printing........using JSP URGENT.PLS

    i have to print some content from the browser and i am using JSP for the dynamic content creation to the browser.
    i am using document.print() in javascript.
    then it is giving the empty space also after printing till the end of the page/document.
    i dont want like this.
    i want the page rolling to be stopped when the content is over.

    >
    i have to print some content from the browser and i am
    using JSP for the dynamic content creation to the
    browser.
    i am using document.print() in javascript.
    then it is giving the empty space also after printing
    till the end of the page/document.
    i dont want like this.
    i want the page rolling to be stopped when the content
    is over.try
    window.focus();
    window.print();

  • I would like to upload a excel file using jsp

    Hi,
    I would like to upload the excel file using jsp in my netbeans ide. Please help.
    I don Know what is the error in this jsp file. It is not showing any thing and the file is also not getting uploaded.
    Please gothru the code below.
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
    <%@ page import="java.io.*" errorPage="err.jsp"%>
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <link href="<html:rewrite page="/design.css" />" rel="stylesheet" type="text/css">
    <title>Upload Page</title>
    </head>
    <body onKeyDown="DisablingBackFunctionality()" onLoad="DisablingBackFunctionality()">
    <html:form action="download" >
    <div style="position:absolute; left:100;top:200;">Select an excel File :<input type="file" name="uploadfile"></div>
    <div style="position:absolute; left:190;top:250;"><input type="submit" name="Submit" value="Read"></div>
    <div style="position:absolute; left:336;top:250;"><input type="reset" name="Reset" value="Clear"></div>
    mainmenu
    </html:form>
    </body>
    </html>
    <%
    String contentType = request.getContentType();
    if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {
    DataInputStream in = new DataInputStream(request.getInputStream());
    int formDataLength = request.getContentLength();
    byte dataBytes[] = new byte[formDataLength];
    int byteRead = 0;
    int totalBytesRead = 0;
    while (totalBytesRead < formDataLength) {
    byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
    totalBytesRead += byteRead;
    String file = new String(dataBytes);
    //out.println("<br> file :"+file);
    String saveFile = file.substring(file.indexOf("filename=\"") + 10);
    //out.println("<br> savefile :"+saveFile);
    saveFile = saveFile.substring(0, saveFile.indexOf("\n"));
    //out.println("<br> now file1 :"+saveFile);
    saveFile = saveFile.substring(saveFile.lastIndexOf("\\") + 1, saveFile.indexOf("\""));
    //out.println("<br> now file2 :"+saveFile);
    //out.print(dataBytes);
    String ext = "";
    if (saveFile.indexOf(".") != -1) {
    ext = saveFile.substring(saveFile.lastIndexOf("."));
    int lastIndex = contentType.lastIndexOf("=");
    //out.println("<br>lst index of"+lastIndex);
    String boundary = contentType.substring(lastIndex + 1, contentType.length());
    //out.println("<br> boundary"+boundary);
    //out.println("<br> file :"+file);
    int pos;
    pos = file.indexOf("filename=\"");
    //out.println("<br> now 0 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 1 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 2 :"+pos);
    pos = file.indexOf("\n", pos) + 1;
    //out.println("<br>now 3"+pos);
    int boundaryLocation = file.indexOf(boundary, pos) - 4;
    int startPos = ((file.substring(0, pos)).getBytes()).length;
    int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;
    FileOutputStream fileOut = new FileOutputStream("D:\\" + saveFile);
    //FileOutputStream fileOut = new FileOutputStream(saveFile);
    //fileOut.write(dataBytes);
    fileOut.write(dataBytes, startPos, (endPos - startPos));
    fileOut.flush();
    fileOut.close();
    session.setAttribute("fil", saveFile);
    //out.println("File saved as " +saveFile);
    %>
    <script type="text/javascript" >
    function DisablingBackFunctionality()
    var URL;
    var i ;
    var QryStrValue;
    URL=window.location.href ;
    i=URL.indexOf("?");
    QryStrValue=URL.substring(i+1);
    if (QryStrValue!='X')
    window.location=URL + "?X";
    </script>
    Please let me know the result as soon as possible. Its my very urgent.
    Thanking Yu,
    Muthu Kumar.R

    No.
    Mylenium

  • Out.print() in a jsp function

    Hi
    I have a jsp page. I have defined a function in it which requests the farm parameters through request.getParameter() and then print it using out.print() but it displays errors on request and out objects.
    How can I use these objects in functions declared in a jsp page.
    Thanks in advance
    Sajid

    Try Like this
    <%!
    public String aFunction(HttpServletRequest request,JspWriter out){
    String sName = request.getParameter("Name");
    out.println("Hai "+sName+" i think you got it now!!!!!!!!!!");
    %>

  • How to create two level dynamic list using JSP , Java Script and Oracle

    I am new in JSP. And i am facing problem in creating two level dynamic list using JSP ,Java Script where the listdata will come from Oracle 10g express edition database. Is there any easy way in JSP that is available on in ASP.NET.
    Plz response with details.

    1) Learn JDBC API [http://java.sun.com/docs/books/tutorial/jdbc/index.html].
    2) Create DAO class which contains JDBC code and do all SQL queries and returns or takes ID's or DTO objects.
    3) Learn Servlet API [http://java.sun.com/javaee/5/docs/tutorial/doc/].
    4) Create Servlet class which calls the DAO class, gets the list of DTO's as result, puts it as a request attribute and forwards the request to a JSP page.
    5) Learn JSP and JSTL [http://java.sun.com/javaee/5/docs/tutorial/doc/]. Also learn HTML if you even don't know it.
    6) Create JSP page which uses the JSTL c:forEach tag to access the list of DTO's and iterate over it and prints a HTML list out.
    You don't need Javascript for this.

  • How to realize print function in JSP

    How to realize print function in JSP? I know use Javascript:window.print() can print,but it will print whole page,it don't fit me;Another method is to write JSP into Excel and then print it in Excel,but it don't fit me too,because it don't print directly. Anybody know how to print it directly?

    Many websites offer a "printer friendly" version of a certain page. That IMO is the only way to solve your problem, next to using CSS to use a different style for printer output. Here is a tutorial that covers this:
    http://www.alistapart.com/stories/goingtoprint/

  • Access Initialization Parameters using jsp

    Hi All,
    Now I'm learning JSP . I want to access the initialization parameters using jsp. How to do it. I used the following code , but it shows null
    initparameter.jsp
        <html>
         <body>
              <h1>
                   <%
                        out.println("InitParameter Checking");
                        out.println(application.getInitParameter("param1"));
                   %>
              </h1>
         </body>
    </html>I configured the following tags in my web.xml.
            <servlet>
              <servlet-name>initparameter</servlet-name>
              <jsp-file>/initparameter.jsp</jsp-file>
            <init-param>
                    <param-name>param1</param-name>
                    <param-value>value1</param-value>
                </init-param>
         </servlet>
                    Help me to resolve this problem
    Thanks in advance,
    mahes

    try overriding the jspInit method and then call getServletConfig() method and call getInitiParameter() on that ..infact the config implicit object would iachieve the same .i don't understand why it's printing null in your case .let me test and see

  • Problem with database using JSP

    Hi
    i am developing one application which uses JSP ..to connect to the database..at present i am using MS-access for the data storage...
    I have two pages in one page there is a form where user fills all the details and once submit the information based on the form has to fetch the data from the backend...i have a problem ..if i hard code the corresponding column name in the JSP page it is getting all the data but if i get it from request.getParameter("")( which i am supposed to be from the form) i am getting no records..
    take a look at the code below and let me know...
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    java.sql.Connection conn= java.sql.DriverManager.getConnection("jdbc:odbc:asiafinity");
    java.sql.Statement stmt=conn.createStatement();
    /* If i print a value from the previous pages its showing but its not going to the database with query statement..
    // String str1=request.getParameter("religion");
    // System.out.println(str1);
    /* If i hardcode the corresponding columun data its querrying the data
    String str1="hindu";
    String sqlquery="select * from userprofile where religion='"+str1+"'";
    System.out.println(str1);
    java.sql.ResultSet cols=stmt.executeQuery(sqlquery);
         while(cols.next()){
    String gen=cols.getString("gender");
    String age=cols.getString("age");
    String rel=cols.getString("religion");
    String cul=cols.getString("culture");
    String loc=cols.getString("location");
    String pro=cols.getString("profession");
    String uname=cols.getString("username"); %>
    <tr><td><a href="<%=uname%>"><%=uname%></td>
    <td><%= gen %></td>
    <td><%= age %> </td>
    <td><%= rel %> </td>
    <td><%= cul %> </td>
    <td><%= loc %></td>
    <td><%= pro %></td>
    </tr>
              <% } %>
    Please help me out..i know this is an simple problem
    Thanks & Regards
    Gnanesh
    </a>

    String str1=request.getParameter("religion");
    String sqlquery="select * from userprofile where religion='"+str1+"'";
    System.out.println(sqlquery);
    try it and tell me what happens

  • Passing values to JavaBean function using jsp scriplet

    Hi,
    I have a JavaBean funtion that is SaveData(parameters)
    which save the values from HTML form.
    Now i want a code for pass the values from HTML form to SaveData() function using jsp scriptlet.
    I used the code
    <jsp:useBean id="JDBC" class="bean.JDBCBean" scope="application"></jsp:useBean>
    <%=JDBC.saveData(phonenumber,manufacturer,model,email,country,newsletter)%>
    Here
    JDBCBean -> Bean Name
    phonenumber,manufacturer,model,email,country,newsletter ->HTML form's text values
    But it didnt work properly.
    Anyone help me to correct this.

    Hi,
    i have the same code like above
    I have to pass the parameters with form name under the following code.
    <jsp:useBean id="JDBC" class="bean.JDBCBean" scope="application"></jsp:useBean>
    <%=JDBC.saveData(registration.phonenumber.value,id_type.value,id_style.value,registration.email.value,registration.scountry.value,player_type.values)%>
    Here
    registration -> HTML form name
    But i got the error for
    package registration does not exist
    out.print(JDBC.saveData(registration.phonenumber.value,id_type.value,id_style.value,registration.email.value,registration.scountry.value,player_type.values));
    How to i correct this?
    Anyone help me......

  • Printing problem in jsp

    Hi...
    I have made an website by using jsp and servlets, the problem is that when click on the print option, to print that jsp page, the links get printed with that, and i want to avoid that link, please help me out from this problem,,thanks in advance...
    Bye n tc

    this is a html/css problem and not a java or jsp one.
    create a css file print.css for example and write the following to this file :
    a{
    display: none;
    }add this to the header of the JSPs you want to print :
    <link rel="stylesheet" media="print" href="/print.css" type="text/css" />

  • Printing document from jsp

    Hi All,
    I am trying to print a document(For example .doc file) from local system using JSP/Servlet. Please note that I dont want to print the current window and I dont want to use applet also. My requirement is that I have to use only JSP/Servlet or javascript for printing the document at client system.
    Please help me with how to do this. Thanks in advance.
    Regards
    Utpal

    That´s not possible. It´s up to the application in which the client is opening the doc file. Which is usually MS Word. That application (un?)fortunately doesn´t understand HTML/Javascript.
    If you have a hard head in this, then you need to create a Java application which does the desired task at the local machine and then embed it as an applet or webstart application in your JSP page. Which is fairly cumbersome imho. Not worth the effort.

  • Dynamic combobox using jsp

    HI All,
    This is very urgent for me please help me to come out of this.
    I just want to display the values in combobox from database using jsp,but i have difficulty in doing it can any one help me for this.I will be thankfull if any one gives me a code for the same.
    Ramesh.R

    very simple example
    <%@ page import="java.sql.*" %>
    Add Item:
    <SELECT NAME="item">
    <ol>
    <%
    Connection con5 =
    DriverManager.getConnection("url","user","password");
    String q5 = "query" ;
    Statement stmt5 = (Statement)con5.createStatement();
    ResultSet rs5 = stmt5.executeQuery(q5);
    while(rs5.next()){
    String str5= rs5.getString("field");
    %>
    <li> <% out.print("<OPTION>" + str5); %>
    <% } %>
    </ol>
    </SELECT>

  • How to open Excel Sheet using JSP?

    Hi Dear,
    I want to open Excel Sheet in client browser, How to do this using JSP?
    If it is possible to open, client can make the changes in the sheet if he saves those changes, those changes must reflect on server.
    So pl. tell me how to do this?
    Thanks

    The following code gets data from an ODBC link to an Excel spreadsheet and displays it as a HTML table. You can modify the table to include <input> fields to update the spreadsheet when the form is submitted.
    I hope that this helps. -Don
    <%
    /* Establish connection to excel database(spreadsheet)
    ODBC DSN="xltest" */
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    java.sql.Connection con= java.sql.DriverManager.getConnection("jdbc:odbc:xltest");
    java.sql.Statement st = con.createStatement();
    java.sql.ResultSet rs = st.executeQuery("SELECT * from [Sheet1$]");
    java.sql.ResultSetMetaData rsmd = rs.getMetaData();
    %>
    <html>
         <head><title>Excel Database connection test</title></head>
         <body><table border=1 cellspacing=0><tr>
    <% // Print Column headings (first row of spreadsheet)
    for (int i = 1; i <= rsmd.getColumnCount(); i ++){
              %><td id='td1'><%=rsmd.getColumnName(i)%></td><%
    }//End for
    %></tr><%
    while(rs.next()) { // Print row data
    %><tr><%
         for (int i = 1; i <= rsmd.getColumnCount(); i ++) {
                   %><td id='td2'> <%=rs.getString(i)%></td><%;}// End for
    }//End while
    st.close();
    con.close();
    %>
    </tr></table></body></html>

Maybe you are looking for