Error on out.println inside declaration block

I am trying to generate a html page from a method iside the jsp page. When I use out.println inside the declaration block (<%! ---- %>) I am getting following error : "Undefined variable or class name: out".
I have tried using System.out.println, but that sends the output to the consol, and not the html page.
What is the workaround for this ??
Following is the test jsp page to illustrate the problem:
<%@page language="java" %>
<%@page import="wt.doc.*" %>
<%@page import="wt.fc.*" %>
<%@page import="wt.query.*" %>
<jsp:useBean id="wtcontext" class="wt.httpgw.WTContextBean" scope="request"/>
<jsp:setProperty name="wtcontext" property="request" value="<%=request%>"/>
<html>
<body>
<%!
     public void prntest(){
          System.out.println("This will print the message only to console");
          out.println("This does not work");
%>
<h1>This is to test out.println function</h1>
<%
out.println("<br>This out.println statement works as expected<br>");
%>
<br>Now try this<br>
<%prntest();%>
</body>
</html>

Hai ,
Here you are trying to access implict object "out" outside the Scriplets ie in function outside the init/service method .
To get output from prntest() , you have pass a reference of JspWriter out to it .ie Your function should be
<%!
public void prntest(JspWriter out2){
System.out.println("This will print the message only to console");
out2.println("This does not work");
%>
<%prntest(out);%>
This should now work .
rakesh

Similar Messages

  • Plz help to solve this error in out.println statement

    Hi All,
    I am pretty new to weblogic8.1.I am Getting a error if i try to concatenate a object to the string in out.println
    statement.
    For your kind reference progam and error pattern is enclosed.
    public class Test extends HttpServlet
    PrintWriter out;
    public void doGet(HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
    out=res.getWriter();
    String aaa="Google";
    out.println("Hai"+aaa);
    ERROR IS:
    Error 500--Internal Server Error
    java.lang.NoClassDefFoundError: java/lang/StringBuilder
         at Test.doGet(Test.java:15)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run(ServletStubImpl.java:971)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:402)
         at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubImpl.java:305)
         at
    weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:6350)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:317)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:118)
         at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppServletContext.java:3635)
         at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestImpl.java:2585)
         at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:197)
         at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:170)
    If i use the statement like;
    out.println("Hai");
    out.println(aaa); ...It works fine
    Plz, help me out there.Thanks All.
    Prith

    My guess is this is a classpath issue. Read weblogic's documentation on how to install the software thoroghly, then re-install it. Double check that JAVA_HOME is set properly, and that you are using a fairly recent Sun Java VM, versus an old MS Java VM...

  • Avoid out.println inside servlet

    Is there a nice way to avoid hardcoding of HTML tag inside the servlet?
    I know it can be done by XML and XSL, but it is hard !!
    Is there any example i can look at to start?
    Is there any other way to do that? I want to separate the logic from the style with static and dynamic content, dynamic stand for "based on the logged on user profile"..
    Thank you.

    Yes, but i have lot of servlet, part of our framework, already implemented (all abstract class), move to JSP mean re-write all this servlet as normal class, i would like to write just a few classes to render html for the specified application.
    I know somebody did using XSL but it is hard to find some good example or tutorial.
    Thank you anyway.

  • System.out.println in EJB

    Hi I have given System.out.println in my EJB object. But I am not able to see the output in my console. But when I give printStackTrace in my JSP(from where I can EJB)....it is displaying the exception....
    So my question is Can we give System.out... in EJB?. Should we set any property to see the output of System.out...in the console?.

    Here is my code
    From UserManager I call the EJB
    public boolean validateSignOn(String strUserName,String strPassword) throws ProdSchedException{
    try{
    UserMgrHome home = (UserMgrHome)getEJBHome("UserMgr",UserMgrHome.class);
    UserMgr userMgr = home.create();
    return userMgr.validateSignOn(strUserName,strPassword);
    catch(RemoteException rex){
    ServerLog.log(rex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(rex,"Server Failed");
    catch(CreateException cex){
    ServerLog.log(cex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(cex,"Create Exception");
    This is my EJB code
    import javax.ejb.*;
    import java.rmi.RemoteException;
    import java.util.*;
    import javax.xml.parsers.*;
    import org.xml.sax.*;
    import org.w3c.dom.*;
    import java.io.*;
    * User Manager Session Bean
    public class UserMgrEJB implements SessionBean {
    SessionContext cntx;
    public boolean validateSignOn(String strUserName,String strPassword) throws ProdSchedException{     
    UserDAO dao = new UserDAO();
         System.out.println("Inside EJB");
    boolean bValidUser = dao.validateUser(strUserName,strPassword);
    if(!bValidUser){
    throw new ProdSchedException("Invalid User");
    return bValidUser;
    //Bean methods
    public void ejbCreate(){
         System.out.println("Inside EJB Create");
    public void ejbRemove(){
    public void ejbActivate(){
         System.out.println("Inside EJB Activate");
    public void ejbPassivate(){
    public void setSessionContext(SessionContext cntx){
    this.cntx = cntx;
    This is mu UserDAO code
    public class UserDAO extends DAO{
    public boolean validateUser(String userName,String password) throws ProdSchedException{
    Connection conn = null;
    PreparedStatement stmt = null;
    ResultSet result = null;
         System.out.println("Inside validateUser in DAO");
    try{
              boolean bIsValidUser = true;
         String selectStatement = "SELECT SYSDATE from DUAL";
         conn = getConnection();
    stmt = conn.prepareStatement(selectStatement);
    result = stmt.executeQuery();
    while(result.next()){
    bIsValidUser = true;
    return bIsValidUser;
    catch(SQLException sqex){
    ServerLog.log(sqex.getMessage(),ServerLog.ERROR);
    throw new ProdSchedException(sqex,sqex.getMessage());
         finally{
    try{
    close(conn,stmt,result);
    catch(ProdSchedException slex){
                   ServerLog.log(slex.getMessage(),ServerLog.ERROR);
    throw slex;
    } // end class
    And the error I get in the console is this(since I have given printStackTrace in my JSP)
    ProdSchedException: SQL Error
    at UserDAO.validateUser(UserDAO.java:
    44)
    at UserMgrEJB.validateSignOn(
    UserMgrEJB.java:26)
    at UserMgrEJB_p3hctp_EOImpl.v
    alidateSignOn(UserMgrEJB_p3hctp_EOImpl.java:46)
    at UserManager.validateSignOn(User
    Manager.java:20)
    at jsp_servlet._public.__login._jspService(__login.java:123)
    at weblogic.servlet.jsp.JspBase.service(JspBase.java:27)
    at weblogic.servlet.internal.ServletStubImpl$ServletInvocationAction.run
    (ServletStubImpl.java:1094)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:437)
    at weblogic.servlet.internal.ServletStubImpl.invokeServlet(ServletStubIm
    pl.java:319)
    at weblogic.servlet.internal.WebAppServletContext$ServletInvocationActio
    n.run(WebAppServletContext.java:5626)
    at weblogic.security.service.SecurityServiceManager.runAs(SecurityServic
    eManager.java:685)
    at weblogic.servlet.internal.WebAppServletContext.invokeServlet(WebAppSe
    rvletContext.java:3213)
    at weblogic.servlet.internal.ServletRequestImpl.execute(ServletRequestIm
    pl.java:2555)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:251)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:219)

  • Multiple Threads Using System.out.println...

    i have a client server app and each client that connects to the server has its own thread.
    i am running the server on a pc using windows xp and to run it i just use a bat file which uses cmd.exe and my output using System.out.println prints out in the cmd.exe.
    each of my threads is using System.out.println to send debug info and outs quite often.
    after the screen fills a scroll bar appears at the right and you can scroll back to see past output.
    my app is all running ok but when i had a ton of output coming in all at once i tried to scroll back to see the older output and realized that if i click down on the scroll bar and fight the new input it freezes my server app. then when i release it it continues lol.
    it made me wonder if output from multiple threads when there are many all at once (say 20 or 30 threads all outputing at the exact same time) could cause a slow down or effect the performance of the server?
    i use a debug variable so i can just turn this output 100 % off except for critical errors so there would be no output but i am just curious as to whether or not it may be causing problems when its on.

    That's not a performance issue, I guess System.out.println() simply gets blocked by the console while you're scrolling and thus your app stalls, until you stop doing that.
    Maybe you should look into logging.

  • While local variable initialized inside try block compiler throws error???

    Check out this code where two local variables(one String and the other int type) is declared at the beginning of the method and initialized inside try block. now when i compile this app, it gives an error sayin' that Variables not been initialized. Can anyone tell me why compiler is throwin' an error message?
    Many thanks.
    import java.io.*;
    public class Test{
    public static void main(String[] args){
    String aa;
    int c;
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    System.out.println("EnterAnything:");
    try{
    aa = in.readLine();
    c = 1;
    catch(IOException e){
    System.out.println(e.getMessage());
    System.out.println(aa);
    System.out.println(c);
    }

    jfbriere,
    Thanks to u all.
    that every reference to the variable is necessarily preceded
    by execution of an assignment
    to the variable.But I've initialized the variable c and aa inside try block before referencing it as a parameter of println()?
    Can u clarify this?
    --DM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • System.out.println statements inside my session beans

    I have some System.out.println statements inside my session beans to track some error conditions. I would like to know where this output will be printed. Is there any text file I should look for or start up any console to see the output.
    I am running iPlanet SP3 test drive edition iPlanet Web Server 4.1 on WIndows NT machine.

    Hi,
    These statements will be printed on the kjs logs file. To view them, go to control panel-> services-> select the iPlanet Application server and click "start up" tab. Check " allow this sevice to interact with the desk top" in the service window that has been popped up. Restart the iPlanet Application server.
    View the kjs window. All your System.out.println statements will be printed out there.
    If you have any further queries please get back to the forum.
    Thanks for visiting our web forum,
    Rakesh.

  • I've deleted Adobe Reader 11 and rebooted and reinstalled Adobe Reader 11 and I still get the error message that 'Adobe Reader is blocked because it is out of date'. Using Windows XP with the latest updates (SP3).

    I've deleted Adobe Reader 11 and rebooted and reinstalled Adobe Reader 11 and I still get the error message that 'Adobe Reader is blocked because it is out of date'. Using Windows XP with the latest updates (SP3).

    Screenshots attached to email replies will not make it back to the forum; you need to login to the forum and post it in your topic using the camera icon in the editor.
    Google Chrome is a problem:
    if you use Chrome's own PDF viewer, the results are unpredictable.
    if you use the Adobe Reader plugin with Chrome, it may reject (block) it if it is not the latest version.  Reader 11.0.08 is the latest version for Windows XP, but Chrome may insist on the current version 11.0.10.
    My suggestion; use a different browser!

  • I have jave 7 I'm trying underscore option in String.   as String strNum = "1000_000";System.out.println("..abc..."  Integer.parseInt(strNum)); but getting error. could you please help in this?

    Hi,
    There is a new feature added in java 7 on integer, called as underscore '_" and it is working fine
    if it is a normal int variable  but if it is coming with String jvm throw the error.
    if  any one of you have java8 installed on your PC can you check this is working on that version.
    int a = 1000_000;   
    String strNum = "1000_000";
    // System.out.println("..abc..."+ Integer.parseInt(strNum));
    System.out.println("a..."+a);
    Thank you,
    Shailesh.

    what is your actual question here?
    bye
    TPD

  • System.out.println()'s inside implementation

    Hello,
    We all know the System.out.prinltn() API. But I want to know the inside implementation of System.out.println() API. Where can I get this implementation?
    Furthermore, can anyone explain concretely about how to implement System.out.println()? Can you tell me in a great detail?
    JohnWen604
    21-June-2005

    I just cannot understand what is the magic behind
    d that one API can control the hardware(i.e. control
    the screen to print one "simple" sentance). Do youIt's called "native OS methods". And you're not controlling anything, the graphics driver does. You're just asking the OS to ask the driver to ask the graphics card to send the appropriate signals.
    think that is just just the magic of our grand new
    computer? So If I can fully understand how the
    hardware is controlled by the Application Program, I
    will be more sensible in writing software. Just likeI doubt that. The more sensible way would be to stick to a useful level of abstraction and good design.
    you know the IC's inner structure if you want to be
    an qualified Electronic Engineer. Do
    you think so?No.
    Besides, from some OS books I know that
    w that Application program written in Java will
    become some OS commands that is ready for going
    through the OS's command processor. I just do not
    understand how that primitive Java code is written
    which is OS command and can tell hardware(screen) to
    print something. Do you know what that primitive Java
    code is?-- The primitive Java code that is a OS
    command to tell screen to print something. The
    primitive java code 's examples are "+", "for",
    "while", "private". The primitive java code does not
    mean API.No. It's called "instructions".
    What you said about setOut0(), I think
    setOut0() is simply an API. Do you know the
    implementation of this setout0() API? There must be
    implementation and there must be the primitive Java
    code. Do you agree with me?No. It's N-A-T-I-V-E. No Java code. Nowhere. Just C++ or whatever.

  • Control Statement inside System.out.println

    I am printing something like this:
    System.out.println(parts1[0] + "|" + parts1[1]); Now, I want to keep a check i.e. if parts1[1] is say 3 I want to printout Hi and if parts1[1] is any other digit I printout Hello. [parts is obtained by using split method from data]
    Can I do it inside the print statement?

    Be judicious about this though. Unless the ternary expression and the overall argument to println are both very simple, you'll end up with an unreadable, unmaintainable mess. The only advantage to doing it all inside the println argument is compactness. If it gets unwieldy, break it up into separate statements, assign the end result to a variable, and print that.

  • How does System.out.println(). Work inside src.zip file !

    Hello guyz,
    I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code. But could not understand it. As written i remember
    "out is an object encapsulated in the System class."
    Thats ok. But i could not understand the code.
        public final static PrintStream out = nullPrintStream();
        private static PrintStream nullPrintStream() throws NullPointerException {
         if (currentTimeMillis() > 0) {
             return null;
         throw new NullPointerException();
        }Also when i ran the DJ Decompiler it decompiled it to this:
    public class One
         public static void main(String args[])
              System.out.println("hello world");
    import java.io.PrintStream;
    public class One
        public One()
        public static void main(String args[])
            System.out.println("hello world");
    }Also, why does it need to import PrintStream ?

    Peter__Lawrey wrote:
    I was just wondering how System.out.println() worked so i opened up the src.zip file and checked the source code.This value is a place holder. This value is changed as soon as enough of the JVM is initialised for printing to work.
    Also, why does it need to import PrintStream ? It doesn't, but it is used in the code so DJ is including it just in case.Sorry,
    But i don't understand at all.

  • System.out.println ....syntax error?

    Hi,
    I am workin on my first java program here...and althought my classes compile just fine I can't manage to get what I want to appear on the screen on Button action....
    Clicking on cost should trigger the appearance of the total cost...but nothing happens.
    Can you have a look and tell me where I went wrong please?
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.util.*;
    public class Booking extends Applet implements ItemListener,ActionListener
    String[][] c = { {"French Language","250","130","70"}, {"Painting","270","140","70"}, {"Yoga","250","130","70"} };
    Courses courses_list = new Courses(c);
    Choice ChoiceCourse;
    Choice ChoicePeople;
    Checkbox cb1, cb2, cb3;
    boolean fulltime = false;
    boolean parttime = false;
    boolean concessions = false;
    Button b1;
    int c1;
    int p1;
    int price;
    public void init()
      add(new Label("Courses available for booking : "));
      ChoiceCourse = new Choice();
      add(ChoiceCourse);
    //the following populates the ChoiceCourse dropDown Menu with the Courses'Titles
      int i=0;
      while (i<c.length)
        ChoiceCourse.addItem(courses_list.getTitle(i));
        i++;
      ChoiceCourse.addItemListener(this);
      add(new Label("Number of participants for the course selected : "));
      ChoicePeople = new Choice();
      add(ChoicePeople);
    //the following populates the ChoicePeople dropDown Menu with "numbers" from 1 to 10
      int j=1;
      while (j<11)
        ChoicePeople.addItem(new Integer(j).toString());
        j++;
      ChoicePeople.addItemListener(this);
      cb1 = new Checkbox ("Full-Time");
      add(cb1);
      cb2 = new Checkbox ("Part-Time");
      add (cb2);
      cb3 = new Checkbox ("Concessions");
      add (cb3);
      b1 = new Button ("Cost");
      add (b1);
      b1.addActionListener(this);
      public void itemStateChanged(ItemEvent e)
       if (e.getSource() == ChoiceCourse)
         String c2 = (String) e.getItem();  // When ChoiceCourse is modified
         if (c2 == "French Language")
           int c1 = 0;
         if (c2 == "Painting")
           int c1 = 1;
         else
           int c1 = 2;
       if (e.getSource() == ChoicePeople)
         String p2 = (String) e.getItem();  // When ChoicePeople is modified
         int p1=Integer.parseInt(p2);       // converts the String into an integer
      public void actionPerformed(ActionEvent e)
        if ( e.getActionCommand() == "Cost" )
          fulltime = cb1.getState();
          parttime = cb2.getState();
          concessions = cb3.getState();
          if (fulltime == true)
            int price = 1;
          if (parttime == true)
            int price = 2;
          else
            int price = 3;
          int mode =  Integer.parseInt(c[c1][price]);  
          System.out.println("total cost of your selection is: �" + courses_list.getCost(p1,mode));
    }

    Thanks for the guidance and the explanations. I've improved my code according to your recommendations (1, 2 &3) and it compiles just fine.
    However, the println still doesn't work...but there is improvement:
    When I run my applet using the AppletViewer at the very end I get a log of what happened...and it's now showing:
    "D:\JBuilder8\jdk1.4\bin\appletviewer.exe Booking.html
    total cost of your selection is: �0"
    Which means that the println is being called but is not printing where it should be (on my screen)....the other problem is that it is obviously not properly calculating the total cost since it shouldn't be �0.
    Here is my new (improved) code, and below is the code for the Courses class (which does some of the calculation):
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.util.*;
    public class Booking extends Applet implements ItemListener,ActionListener
    String[][] c = { {"French Language","250","130","70"}, {"Painting","270","140","70"}, {"Yoga","250","130","70"} };
    Courses courses_list = new Courses(c);
    Choice ChoiceCourse;
    Choice ChoicePeople;
    Checkbox cb1, cb2, cb3;
    boolean fulltime = false;
    boolean parttime = false;
    boolean concessions = false;
    Button b1;
    int c1;
    int p1;
    int price;
    public void init()
      add(new Label("Courses available for booking : "));
      ChoiceCourse = new Choice();
      add(ChoiceCourse);
    //the following populates the ChoiceCourse dropDown Menu with the Courses'Titles
      int i=0;
      while (i<c.length)
        ChoiceCourse.addItem(courses_list.getTitle(i));
        i++;
      ChoiceCourse.addItemListener(this);
      add(new Label("Number of participants for the course selected : "));
      ChoicePeople = new Choice();
      add(ChoicePeople);
    //the following populates the ChoicePeople dropDown Menu with "numbers" from 1 to 10
      int j=1;
      while (j<11)
        ChoicePeople.addItem(new Integer(j).toString());
        j++;
      ChoicePeople.addItemListener(this);
      cb1 = new Checkbox ("Full-Time");
      add(cb1);
      cb2 = new Checkbox ("Part-Time");
      add (cb2);
      cb3 = new Checkbox ("Concessions");
      add (cb3);
      b1 = new Button ("Cost");
      add (b1);
      b1.addActionListener(this);
      public void itemStateChanged(ItemEvent e)
       if (e.getSource().equals (ChoiceCourse)) //should this be == or .equals? it doesn't work either way but compiles
         String c2 = (String) e.getItem();  // When ChoiceCourse is modified
         if (c2.equals ("French Language"))
           c1 = 0;
         if (c2.equals ("Painting"))
           c1 = 1;
         else
           c1 = 2;
       if (e.getSource().equals (ChoicePeople)) //should this be == or .equals?it doesn't work either way but compiles
         String p2 = (String) e.getItem();  // When ChoicePeople is modified
         p1=Integer.parseInt(p2);       // converts the String into an integer
      public void actionPerformed(ActionEvent e)
        if ( e.getActionCommand().equals ("Cost") )
          fulltime = cb1.getState();
          parttime = cb2.getState();
          concessions = cb3.getState();
          if (fulltime)
            price = 1;
          if (parttime)
            price = 2;
          else
            price = 3;
          int mode =  Integer.parseInt(c[c1][price]);  
          System.out.println("total cost of your selection is: �" + courses_list.getCost(p1,mode));
    class Courses
    import java.util.*;
    public class Courses
    private String[][] Listing = new String[3][4]; //create array 3 rows * 4 columns
    Courses(String[][] c)
       this.Listing=c;
    int i;
    int j;
    int p;
    int price;
    int people;
    int cost;
    String t;
    String p1;
    String getTitle(int i)  //return Course Title
       t=Listing[0];
    return t;
    int getPrice(int i, int j) //return Price (Full-Time, Part-Time, Concessions)
    p1=Listing[i][j];
    p=Integer.parseInt(p1);
    return p;
    int getCost(int pe, int pp)
    pe=price;
    pp=people;
    cost=pe*pp;
    return cost;

  • Can't throw exception inside try block!

    Hi,
    I'm having a problem trying to throw an error inside a try block.
    To illustrate:
    public class TestException {
    public TestException() {
    try {
    int ret = foo();
    System.out.println("ret is " + ret);
    } catch (Exception ex) {
    System.out.println("exception caught");
    public int foo() throws Exception {
    int ret = 0;
    try {
    throw new Exception("test exception");
    } finally {
    return ret;
    public static void main(String[] args) {
    new TestException();
    If I run this the only output is "ret is 0" - I do not catch the thrown exception! What am I doing wrong?
    Any and all help will be very gratefully received.
    Thanks.

    I need to correct myself: I've re-read the spec, and actually the behaviour is conformant with the JLS: JLS says that the return statement completes abruptly, and an abrupt return in a finally block that didn't have a (applicable or any) catch block will result in the original exception being 'forgotten'.
    Very unintuitive, but as-spec'ed

  • Error while adding code inside validateEntity()

    Hi,
    Requirement is there is a custom table on custom OA Page which is updatable. If we change any value in the table the process_flag attribute should be changed from E to N.
    I tried putting code in EOImpl validateEntity()
    protected void validateEntity()
    super.validateEntity();
    Number trxId = (Number)getTransactionId();
    setProcessFlag("N");
    System.out.println(" Row Modified for trx "+trxId+" "+valDated);
    I am getting error
    oracle.jbo.ValidationException: JBO-28200: Validation threshold limit reached. Invalid Entities still in cache
    If i comment setProcessFlag it is successfully printing trxId whcih records was changed.
    If we are not supposed to set Entity Attribute value in validateEntity() what is the best way to achive this ?
    Thanks,
    Abhi

    Hi Pradeep,
    I tried putting setProcessFlag("N");
    method inside create method of EOImpl. It is not working.
    I tried vo.isDirty() that is also not picking from AM.
    Requirement is to identify row if any column changed if yes Change flag.
    Thanks,
    Abhi

Maybe you are looking for