Print statement in JSP page after redirection

Hi,
I have written a JSP page and in that i am redirecting it to another page. Now after redirection i am printing a statement on the console. It is getting printed whereas when i am printing the same on the browser i am not able to print that. Please can any one tell me the difference between printing the same on the console and browser.
My first JSP page(one.jsp)
<%
     response.sendRedirect("two.jsp");
     out.println("After redirect");
     System.out.println("After out");
%>
My second JSP(two.jsp)
<%
     out.println("In two.jsp");
%>
Thanks in advance
regards
Prashanth

The sendRedirect sets a code in the HTTP response being sent to the client (I believe it is a 302 code but I am not sure off hand) and then proceeds to process the rest of the JSP on the server which is why the print statement shows up in the console.
The out.println writes to the HTTP response output stream. The client gets the response and sees the HTTP Header code telling it to make a new request so it stops processing the response message and sends a new request message which is why the out.println message is not seen in the browser.

Similar Messages

  • How to redirect a JSP page after the session is killed

    Hello!
    I am quite new to JSP. I have a question about how to redirect a jsp page after the session is killed. Could anyone help?
    thanks a lot in advance!

    You can't, directly. There's no connection betweenthe server and browser.
    even after invalidating the session. we can do it
    directly using the statement
    response.sendRedirect("....");
    or we can use the meta refresh tag.if session is invalidated and if we try to do response.sendRedirect(".. ") it throws IllegalStateException

  • Problem with printing debug statements in JSP page

    Hi all,
    I am debugging an application with System.out.println() statements - my debug statements in the *.java class printed just fine, but when I do the same thing in my JSP page, nothing gets printed out.
    I am already wrapping my System.out.println() statements inside the <% %> tag.
    Does anyone know what may be causing this? Any help will be greatly appreciated!
    - JL

    Where do you expect to see the output?
    System.out.println will write to the console/logs
    They WON'T write to the JSP page.
    If you check your error/output logs you will probably find the statements there.
    If you want to print things into the JSP page, just use out.println.
    "out" is an implicit reference to the current JSPWriter.
    Cheers,
    evnafets

  • How to print report in jsp page?

    excuse me,i am new to jsp
    may i know how to pritn report in jsp page or html?
    tq

    here is a hacked up example.. i ripped out a lot, so it may not compile, but you get the idea... the full version is really long and not much new info.. just all awt/display stuff...
    package rowe;
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.image.*;
    import java.awt.event.*;
    import java.sql.*;
    import utility.*;
    import java.awt.print.*;
    public class rowePrint extends JFrame implements ActionListener, Printable{
         String printType = "";
         static JButton j = new JButton("Print");
         FontMetrics fm;
         String jID, promotion, product, jComments;
         public void getInfo(int jid) {
              ResultSet rs;
              try {
                   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
                   Connection conn = DriverManager.getConnection("jdbc:odbc:rowe");
                   Statement stmt = conn.createStatement();
                   rs = stmt.executeQuery("select j.id as jID, j.comments, p.title as pTitle, p.product, p.packagingCartonCost, p.foldingQuarterCostPerM, p.foldingQuarterCostPerM, j.customizationOption as setupFee, p.perMcost, p.qtyCarton, d.name as dName, d.contact as dContact, d.email as dEmail, d.address as dAddress, d.city as dCity, d.state as dState, d.zip as dZip, d.phone as dPhone, d.fax as dFax, r.name as rName, j.totalQty, j.orderIn, j.estFreight, j.miscCost, j.coverSelection, j.imprintSelection from jobs j, promotions p, dealers d, reps r where j.promotion = p.id and j.dealer = d.id and j.rep = r.id and j.id = " + jid);
                   rs.next();
                   jID = rs.getString("jID");
                   jComments = rs.getString("comments");
                   promotion = rs.getString("pTitle");
                   product = rs.getString("product");
              } catch (Exception e) {
                   System.out.println("getinfo: " + e);
       public void actionPerformed(ActionEvent e) {
            if (e.getSource() instanceof JButton) {  
                   wookie();
         public void wookie() {
              PrinterJob printJob = PrinterJob.getPrinterJob();
              Paper paper = new Paper();
              PageFormat page = new PageFormat();
              paper.setImageableArea(0, 0, 600, 780);            
              page.setPaper(paper);
              printJob.setPrintable(this, page);
              try{
                   //printJob.pageDialog(page);
              //     if (printJob.printDialog()) {
                        printJob.print();
              } catch (Exception e) {
                   System.out.println("wookie1" + e);
         public static void main(String[] args) {
              rowePrint at = new rowePrint("Invoice");
              at.getInfo((new Integer(args[0])).intValue());
              at.drawShapes();
         //     at.wookie();
         public void drawShapes() {
              setBounds(0, 0, 670, 550);
              addWindowListener(new WindowAdapter() {public void windowClosing(WindowEvent e) {System.exit(0);}});
              j.setBounds(10, 10, 10, 10);
              j.addActionListener(this);
              getContentPane().setLayout(null);
              getContentPane().add(l);
              getContentPane().add(j);
              show();
         public rowePrint(String s){
              printType = s;
         public void paint(Graphics g) {
              g.setFont(new Font("Serif", Font.BOLD, 18));
              g.drawString(promotion, 20, 30);
              g.setFont(new Font("SansSerif", Font.PLAIN, 4));
              g.drawString("" + new java.util.Date(), 20, 37);
              g.setFont(new Font("Serif", Font.BOLD, 21));
              g.drawString("Rowe Furniture", 440, 35);
              g.fillRect(440, 40, 145, 25);
              g.setColor(Color.white);
              fm = g.getFontMetrics(new Font("Serif", Font.BOLD, 21));
              g.drawString(printType, 512 - (fm.stringWidth(printType) / 2), 60);
        public int print(Graphics g, PageFormat pf, int pi) throws PrinterException {
            if (pi >= 1) {
                return Printable.NO_SUCH_PAGE;
              paint(g);
            return Printable.PAGE_EXISTS;
    }

  • Print Button on JSP page prints title,time etc

    Hi I have aprint Button on my jsp page which prints whatever I want selectively using the <style tags>
    <style type="text/css" media=print>
    .noprint { display: none}
    .noscreen { color: black }
    </style>
    <style type="text/css" media=screen>
    .noscreen { display: none}
    .noprint { color: blue }
    </style>
    <SCRIPT Language="Javascript">
    function printit(){
    window.print();
    </SCRIPT>
    My print Button calls the JavaScript and prints everything that does not have a class=noprint in it... When I print however it also prints on the page
    -The Title on the Left Top corner
    - Page 1 of 1 on RIGHT TOP
    - 2/13/03 on Left bottom
    - 4:06 thats the time on the RIGHT BOTTOM
    Is there anyway I can prevent it from printing this?

    These probably come from the browser. Check if your browser is configured to print these on every page that is printed. If so, you can turn these of from the browser's Page Setup dialog.

  • How to print report from JSP Page

    Hi Everybody,
    I am developing a simple project in JSP with MS Access. I hav some tables and reports for them. I hav a JSP page which gets inputs from user and save it in the table. Its working fine. But my problems are,
    1) I hav a button called "SAVE & PRINT" in that bottom of the page, if i click that button, the currently entered data has to save in the table and the same data has to print from the MS Access report. I dont know how to print this report from JSP page.
    2) Another button called "REPRINT". If i click that button, it has to ask a number to print the report page, that number is nothing but a field in that report.
    Could anyone help me to solve this problem.

    Hi Everybody,
    I am developing a simple project in JSP with MS Access. I hav some tables and reports for them. I hav a JSP page which gets inputs from user and save it in the table. Its working fine. But my problems are,
    1) I hav a button called "SAVE & PRINT" in that bottom of the page, if i click that button, the currently entered data has to save in the table and the same data has to print from the MS Access report. I dont know how to print this report from JSP page.
    2) Another button called "REPRINT". If i click that button, it has to ask a number to print the report page, that number is nothing but a field in that report.
    Could anyone help me to solve this problem.

  • Regarding comment statement in JSP Page

    Hai to All,
    I have written one small jsp page which checks the given name and display the entered name. This is the code which i have written. Its working fine.
    <html>
    <%
    String name = request.getParameter("txtName");
    out.println("THe Name is"+name);
    out.println("<br><br><br>");
    if(name.equals("Balaji"))
    %>
    <input type=Label value="Welcome Balaji">
    <%
    else
         if(name.equals("Kumaran"))
         %>
         <input type=Label value="Welcome Kumaran">
         <%
              else if(name.equals("Kandhan"))
              %>
              <input type=label value="Welcome Kandhan">
              <%
         else{
              %>
              <input type=label value="Welcome!!! Welcome !!!!">
              <%
              %>
    <h3> Code Ends Here</h3>
    </html>
    But if want to comment an else if block like this it shows some error like else without if.... delete else token. can someone please help me.
    <html>
    <%
    String name = request.getParameter("txtName");
    out.println("THe Name is"+name);
    out.println("<br><br><br>");
    if(name.equals("Balaji"))
    %>
    <input type=Label value="Welcome Balaji">
    <%
    else
         if(name.equals("Kumaran"))
         %>
         <input type=Label value="Welcome Kumaran">
         <%
         /*     else if(name.equals("Kandhan"))
              %>
              <!--
              <input type=label value="Welcome Kandhan">
              -->
              <%
         else{
         %>
         <input type=label value="Welcome!!! Welcome !!!!">
         <%
         %>
    <h3> Code Ends Here</h3>
    </html>

    <!--
    <input type=label value="Welcome Kandhan">
    -->That is an HTML comment, not a Java comment. So it gets sent to the client with Java code that looks like this (sorta):
    out.println("<!--");
    out.println("<input ...>");
    out.println("-->");So that means, between the end of the previous if statement there is some java code (the out.printlns) before you get to the else, which isn't allowed.

  • Print version for JSP pages

    Hi,
    I have the following requirement. I have a site consisting of JSP pages. I need to provide a print version for every page.
    The problem is, while printing, if a webpage spans for multiple printing pages, I need to put a footer on each of these pages. But, this footer must appear only once (at the bottom of the page).
    How do I achieve this? any help will be greatly appreciated.

    there is one work around for doing this... in order to print the header and footer...generate a dummy page with the exact format...
    Header
    20-25 Lines Text
    Footer
    Header
    20-25 Lines Text
    Footer
    and so on...
    so when this is flushed to the printer....u would get every page formatted with Header and Footer as this is going to happen in the background...there willl be no pblm to users...
    hope this helps u...

  • Printing the populated JSP page

    I'm generating the student reports of all the students in a class. I've the data in form of beans in my servlet. i can forward to a JSP and display the reports of the students one by one. as soon as the report is generated, i want the JSP page to be printed. what java api can i use for it? or any other alternative for this?

    JavaScript has a way of printing the page. But that would be certainly on the client side and the client machine needs to have a printer. :P
    Sample:
    <input type="button" value="Print This Page" onClick="window.print()">

  • Printing a wide jsp page

    Hi Friends,
    I have a jsp page displaying some information.It is wide and I have to scroll side ways to see the complete page.Its 2 to 3 times the actual width of the screen.But when I take a print out only the part which is visible is printed and the remaining part which is to the side is truncated.Is there a way so that I can take a print out of the entire width of the page.
    Thanks in Advance for your help.
    (Anthony)

    Hi,
    Thanks for your time.
    I am using tables but the no. of columns in the table are more and it grows dynamically thus becoming a wide report.My requirement is to print the complete report however wide it is.
    please let me know if you have a solution
    thanks,
    Anthony

  • Remembering the radio button state between jsp pages

    How do i maintain the state of radio buttons when i move from one jsp page to another. Thank you for your help.

    Hi
    If the next JSP is a child window,you can take a JSP hidden variable and you can store radio button state in it and can get the same on child window thorugh window.opener.
    And if its not a child window(JSP),then you can maintain the state in session and get it anywhere.

  • Redirect to the jsp page after user authenticated successfully  …

    Here is the requirement …
    I’m using “JAAS – Custom Login Module” for user authentication.
    I have few questions in Portal Logon process …
    1. Exactly at what point I can conclude that the user has been authenticated successfully, because I have to redirect the user to some other page for the first time logon to enter some information, subsequent logins shouldn’t be redirected. (I can update flag upon entering information).
    2. Where should I add my redirection code? Is it in my JASS Custom Login Module?
    If yes, how can I do that ? I’m more consider on “where should I add it”?
    3. Do I need to change my “UmLogonPage.jsp” to complete my requirement?
    4. Once after entering the Logon information, who will call my JASS – Custom Login Module for authentication? If authentication has failed who will return the control back to the “umLogonPage.jsp”?
    5. In my JASS Custom Login Module, I have no redirections except having logic for authentication process, and some Login Exceptions are thrown for failure logins.
    6. Who will catch these exceptions for failure logins to redirect back to the “umLogonPage.jsp”.
    7. Finally I like to know where can I add my redirection logic once the user has been authenticated successfully?
    8. last but not least can any of the experts explain the whole login process (using JASS module)? How the control goes from one component to another?
    Any kind of help is appreciated.
    Points can be awarded for useful answers.
    Thanks
    MMK

    Thanks a lot for your valuable reply.
    yes what you said was correct, storing information in R/3 System and getting the details from FM using Connector framework.
    You said i have to modify "header.jsp", can you please tell which .par file should i get to modify?
    one more question to you ... i have provide custom logon error messages to the user ... i did all the modification in logon.par and deployed in EP 6 .. working fine .. i can able to see "User ID Missing" , "Password Missing" etc ..
    when i place same peace of code in EP 7 it always displaying "User Authentication failed". can u guess what whould be the problem?
    Thanks
    MMK

  • Printing table in JSP page

    Hi friends,
    i am developing an web application where customers and vendors can able to view a detailed report of what are all the product they purchase/sold. Here i need to print that report and not the whole page.. I think i am clear my point. Please help me do accomplish this.. I don't want my whole site design to be printed, instead print that particular table that contains the report... Any help will be appreciated... Please help me get rid of this....

    1) Design a CSS rule with an @media print rule that hides everything except the table to be printed
    2) Make your table its own JSP. Have it included in your normal screen display. Then provide a "Printable Version" that is a new JSP that skips most of your UI and just includes the table (and whatever HTML markup around it is necessary). Have a link on the regular page that says 'View Printable Version'.

  • Printer dispenses a blank page after every printing!

    Suddenly my printer is dispensing a blank sheet of paper after almost every printing. Oddly, the only thing unusual I've done, relating to the hp printer,  is downloading the HP Printer Assistant and the HP Printer and Scan Doctor! I've checked all relative settings and nothing seems out of the ordinary or different.

    Hi @ibgb 
    Another user recently posted what he/she tried to resolve this same issue. Perhaps it might work for you too;
     I reset my top and bottom margins and test printed and scanned and it did not put out any blank sheets.  - Source
    If this doesn't resolve the issue, please try the following;
    1. Touch the Windows key on the keyboard to get to the start screen, then without clicking anything type Devices and Printers, and tap or click the Devices and Printers icon.
    2. Right click on the printer icon and click on printer properties.
    3. Then click on Advance Tab, and click on the Separator Page tab.
    4. A small windows open with the location of the file. Delete the path, click ok to save the settings.
    I hope this helps.
    Please click the Thumbs up icon below to thank me for responding.
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution.
    Sunshyn2005 - I work on behalf of HP

  • Error msg in IF ELSE statement in jsp page, Need help

    Below is my code I am trying to execute, but keep getting an error:
    Compilation error occured:
    Found 1 errors in JSP file:
    D:\\http\\proFolder\\student.jsp:130: Syntax: "}" inserted to complete StatementNoShortIf
    <%if (assess.getNumberValue() > 0) {%>
         <%if ((assess.getTotalCost(appForm)) <= (assess.getNumberValue())) {%>
         <strong><%=assess.getTotalCost(appForm)%></strong>      
            <%}%>
    <%}%>
    <%else {%>
         <%=assess.getTotalCost(appForm)%>
    <%}%>Basically, What I am trying to do is follow this logic:
    IF method getNumberValue() is greater then 0, then execute the second IF statement that
    is, If method getTotalCost() is less then or equal to getNumberValue() then display value of method getTotalCost()
    End Second IF
    End First IF
    Now if the First IF fails ( that is getNumberValue() is not gether then 0)
    then execute the else statement
    Could someone please guide me what I am doing wrong, and what would be the correct way of write the IF else code
    Thanks,

    <%     if (assess.getNumberValue() > 0) {
              if ((assess.getTotalCost(appForm)) <= (assess.getNumberValue())) {
    %>
                   <strong><%=assess.getTotalCost(appForm)%></strong>      
    <%          
    %>
    <%
         else {
    %>
              <%=assess.getTotalCost(appForm)%>
    <%
    %>

Maybe you are looking for

  • Updating to 10.6.4: slow boot (10+ mins) and unannounced shutdowns

    Hey guys, I've been having some issues with my trusty MacBook lately and I'm kinda lost on what to do next. Let's start with a short description of the problems: 1. About a week ago the charger was not working sometimes when I connected it (cleaned t

  • HELP ipod not recognised on PC

    Help My Ipod does not show up on my PC. It does not dingdong when you plug it in. I have tried another ipod I have got ang that still picks up on the PC. I have tried restoring the Ipod, I have reinstalled Itunes, and I have checked the drivers on th

  • Website within a website

    In order to view a new website on the internet that I am creating, I have put the whole website file in a folder within an existing website. Both websites have templates and files with the same names. The only difference is the new website is in a fi

  • Goods Issue form

    Hi all, I want to see the output of the standard form WESCHEINVERS3 for goods receipt.through which transaction i can c the output.and which is the application where i can attach the form in NACE. Regards Lalit

  • DEFECT: Locks up on save of object being used elsewhere

    When I try to save an object (such as a package body), Oracle (quite rightly) will not let me replace the object's code if some other process is using that object. However, SQL Developer handles this situation in a very, very unpleasant manner. Basic