Calling out.println in a jsp function

Hi, i want to call out.println in a jsp function. That is i am using function like this
<%!
void MyFunction()
out.println("this is good");
%>
This code fails with error message: "out cannot be resolved"
Also i don't want to return value from the function, since i will later call this function recursive and display value at each instant.
Please suggest any solution.

<%!
void MyFunction(JSPWriter out)
out.println("this is good");
%>and then execute it with:
<% MyFunction(out): %>

Similar Messages

  • 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 can I show a System.out.println(""); into a JSP?

    Is a simple doubt that would help me a lot to reach other thing that I wished reach with a JSP.
    Thank you!!!

    Hi!!!
    Thank you to answer me......my question�is because�my problem is a little more complicated��let me tell you�.
    My problem is that I wish to do some queries to a table of a Municipalities DB, I have read about that....and according with the exemples....my JSP...should be running and executing very well....but I haven�t had success with that...:(
    My JSP file is:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    stmt.execute("select * from cat_municipio");
    ResultSet rs = stmt.getResultSet();
    while (rs.next()) {
    System.out.println(rs.getInt("cve_municipio") + " - " + rs.getInt("cve_sepomex") + " - " + rs.getString("desc_municipio"));
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    My result obtained is the following:
    Municipalities List
    Please call Mary with any updates ASAP!
    Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    I don�t obtain nothing.....is like DB table were without information......but in reality the DB table has information.....and I can obtain it with the following JSP:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    // Fetch all records from the database in a TableDataSet
    DataSet dSet = new TableDataSet(conn, "cat_municipio").fetchRecords();
    TableElement tE = new TableElement(dSet);
    tE.setBorder(1);
    out.print(tE);
    } catch (SQLException sqle) {
    out.print("Sorry, the database is not available.");
    out.print("Exception: " + sqle);
    } catch (Exception e) {
    out.print("Exception occured: " + e);
    } finally {
    if(conn != null)
    try {
    conn.close();
    } catch(SQLException sqle) {}
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    and with this JSP I obtain all the following information:
    Municipalities List
    CVE_MUNICIPIO CVE_SEPOMEX DESC_MUNICIPIO
    1 1 ACAJETE
    2 2 ACATENO
    3 3 ACATLAN
    4 4 ACATZINGO
    5 5 ACTEOPAN
    Now...I need that the first JSP work very well, because...with that way...I can do queries and obtain the needed results for showing them in the Browser......
    So, I already find out�.that�any string that I send to the browser with System.out.println(); isn�t showed�.so it is the reason of my question�..how I can see my results of a query using a loop (like a for, while) resolving it....I think my problem would be resolved.
    So...I hope you understand me, and you could help me please...thanks.....
    Mary
    P.D. I also attempted with the following JSP...but the result is the same....I don�t obtain none result...
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select CVE_MUNICIPIO, CVE_SEPOMEX, DESC_MUNICIPIO from cat_municipio");
    while (rs.next()) {
    System.out.println(rs.getInt(1) + " - " + rs.getInt(2) + " - " + rs.getString(3));
    rs.close();
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>

  • System.out.println in Servlets/JSPs

    Hi,
    Which file and directory in JDeveloper 10g (10.1.3.0) on windows does the output of System.out.println get logged to? THanks in advance.
    regards,

    Goes to standard out, not a file. So if you're running the embedded server you will see it in your Embedded Server Console window. However, you should never be using system.out.println in a servlet/jsp. Instead use commons logging or log4j to get log messages.

  • System.out.println and Network Adapter problem

    Hello,
    I am encountering a 2 strange problems. I have 2 oracle application server instances, one dev and one production.
    The first problem is when I type System.out.println in the JSP's i am able to see the output in both \opmn\logs\oc4jinstance. But the System.out.println in the java classes or bean show up only in development logs but not in production box.
    Is there a setting I am missing here?
    The second problem is on our development machine the application works fine, but as soon as we deploy the application on production I encounter:
    could not open new connection: Io exception: The Network Adapter could not establish the connection
    I have a class called DBUtils, which uses a 3rd party library to get connections from the connection pool as below. Using JSP I call the getConnection(). On my dev Oracle Application Server Instance it works fine, but on production I get the error. Can it be there is a setting that I am missing on the production box?
    When I use a JSP and connect to the database without using the DBUtil class. I can connect to the database fine. Also using the DBUtil class with production oracle IP address on the development machine lets me connect with no problem, but production machine does not let me.
    public class DBUtils {
    static ConnectionPoolBean pool;
    static {
    System.out.println("DBUtils() - before connection pool bean");
    pool = new ConnectionPoolBean();
    pool.setDriverClassName("oracle.jdbc.driver.OracleDriver");
    pool.setdbURL("jdbc:oracle:thin:@IPADDRESS:PORT:SID");
    pool.setUser("USERNAME");
    pool.setPassword("PASSWORD");
    pool.setInitialConnections(1);
    pool.setIncrement(1);
    pool.setSoftMaxConnections(40);
    public static Connection getConnection() throws SQLException {
    System.out.println("Getting Oracle Connection");
    return pool.getConnection();
    public static void returnConnection(Connection conn) throws SQLException {
    System.out.println("Returning Connection");
    pool.returnConnection(conn);
    Thanks for your help in advance.

    Hi
    System.out.println is a method of PrintStream in IO which is used to print the output on console in java progs.Here in jsp ,the o/p is printed on server's console window.But out.println is totally different as, out is implicit object derived from JspWriter and is used sly to PrinWriter 's object is used in servlets.It's work is to write upon Browser.
    System.out.println() is normally used in jsp for debugging purposes only.
    Ashish

  • How to use sswa jsp function in personalization?

    I have a question. When I add a custom item of type link in a region using personalization, how can i access the click of the link as an event in that region';s controller.
    Also if I want to use the "destination function" field of the new Link created with an existing seeded SSWA JSP function, how do i pass url parameter values to this function.
    The function name is IMC_NG_PER_SOURCE_VIEW and the HTML call is OA.jsp?page=/oracle/apps/imc/ocong/mosr/webui/ImcPerMosrViewPage&ImcPartyId={@ImcPartyId}&ImcPartyName={@ImcPartyName}&ImcMainPartyId={@ImcMainPartyId}
    Now when I click the link on the Page the HTML call is made as is, i.e. the target Page ImcPerMosrViewPage gets the value for ImcPartyId = "{@ImcPartyId}" instead of the real Party ID.
    Whereas on the same Page there is a side bar Menu, and one of the Menu item makes a call to the same sswa jsp function and when we click the menu item the target page is rendered successfully.
    So my question is how do I make the link on the region to work the same way as the Menu item.
    It would be great of you could share some tips to resolve this issue of mine.
    Many Thanks!
    Jay

    Just set the fire Action property of that link and capture that in controller PFR.
    Thanks
    --Anil                                                                                                                                                                                                           

  • Lost System.out.println statements.

    Hi
    I have few system.out.println in my jsp which i am using in my JSP provider channel. but when I look at the portal server's /var/opt/SUNWam/debug/desktop.debug file, none are there.. I looked at the web server's access and error logs too, but it is not there also.. can somebody tell me how do it get those ?? do we have any other mechanism to put debug logs ?

    By default the binary which web server runs is uxwdog which eats up System.out.println output. If you want to see the System.out.println then you need to change the product binary from the start script of the portal server instance.
    - Go to <portal-install-dir>/SUNWam/servers/https-<instance-name> and open the start script
    - Change the PRODUCT_BIN=uxwdog to PRODUCT_BIN=ns-httpd , save the file
    - Run the script ./start to start the portal server
    Note : with ns-httpd ON the server will not leave that shell, and in the same window/shell you will be able to see all your System.out.println statements. To close the server you have to kill the server process with "kill -9 pids" command
    Alternate way is to use api inside your application or jsp:
    <%@page import="com.sun.portal.providers.jsp.JSPProvider, com.sun.portal.providers.*, com.sun.portal.providers.containers.*, com.sun.portal.providers.context.*" %>
    <% JSPProvider p=(JSPProvider)pageContext.getAttribute("JSPProvider");
    ProviderContext pc = p.getProviderContext(); %>
    <%-- after that you can use these lines any where in your jsp --%>
    <%
    pc.debugError("your error msg");
    pc.debugMessage("your msg");
    pc.debugWarning("your warning msg");
    %>
    The perticular mgs will be shwon in /var/opt/SUNWam/debug/desktop.debug file as per your "debugLevel" parameter setting in /etc/opt/SUNWps/desktop/desktopconfig.properties file. By default the debugLevel is set to error so only pc.debugError("error msg") will be shown.
    Sanjeev

  • Synchronized use of System.out.println()

    So I am again at the point of part of my program running ahead of itself out of the call stack and ruining the sequence or order of printing.
    I read that System.out.println() is synchronized so how may it be used to wait() until notified to continue and not ruin the output?

    jverd wrote:
    Always Learning wrote:
    YES SIR EJP! SIR! I thank you for the assistance because using only System.out and synchronizing worked beautifully.You said you're not using multiple threads. If this is true, then there's no reason to synchronize anything. The output will appear on System.out in exactly the order you send it there.
    Nos if only I could figure out dependencies to make it work with out and err.You have to stop and think about it for a minute. You know that when you call println() on either one of those two streams, the output may be buffered an not necessarily go immediately to the console. From that you can reason that if you call out.println() first, and then err.println(), that you could end up with err's buffer getting flushed first, and the output appearing on the console in a different order than that in which your code executed the calls.
    You are of course not surprised by this, given that you know that out and err are completely independent and just happen to end up at the same destination in this particular case.
    So, as a first guess, you might reasonably think that, since buffering is obviously the culprit here, calling flush() on each stream after each print() or println() call should eliminate the problem. In a multithreaded environment, this wouldn't be sufficient, of course, but it's a logical approach to try here.
    Another tidbit to make note of is that the System class has setOut() and setErr() calls. Since you're looking at out and err in the same console, you presumably don't care about the distinction between them (which makes me wonder why you're using them both in the first place, instead of just using one). If you're just going to mush them together into the same console anyway, then you can use setOut() or setErr() to make them the same stream, and things will be ordered as you expect.Very interesting Jverd and I think there may yet be life in what I would like to do. I did not know or was not immediately aware of these things. I will give it a try.
    To answer your question, I am using them both because, like logging, they are distinct in the Eclipse console (black for out and red for err). With your patch I just tried that distinction has faded but the output is sequenced the same so I do appreciate you noting this. Learn something new in Java each time I am doing a project. I considered using logging and putting errors in a window but I am not sure if I should do that; just not enough experience with it.
    Edited by: Always Learning on Oct 23, 2011 9:28 AM

  • In a JSP having a problem using out.println in method

    I am trying to update a field on a form using JAVASCRIPT generated by JSP. The following code works fine when in the main body of the code.
    The field tota on form mainform is updated based on the contents of strTest.
    out.println("<SCRIPT LANGUAGE='JavaScript'>")
    out.println("document.mainform.tota.value = " + strTest);
    out.println("document.mainform.tota.focus()");
    out.println("</SCRIPT>");
    But if you have 10 flds that you want updated, it would be nice NOT to have to use 40 lines of code to do it. I am trying to build a method that will accept a field name and some data to put in a form field. I started small and just wanted to update 1 fld using the method below:
    <%!
    //Declare method to update form fields
    void Update_Frm_Fld()
    out.println("<SCRIPT LANGUAGE='JavaScript'>")
    out.println("document.mainform.tota.value = " + strTest);
    out.println("document.mainform.tota.focus()");
    out.println("</SCRIPT>");
    %>
    I keep getting the error:
    Time_Entry_jsp.java:21: cannot resolve symbol
    symbol : variable out
    location: class org.apache.jsp.Time_Entry_jsp
    out.println("");
    ^
    Help.....

    try this:
    <%@ page import="java.io.*" %>
    <%!
    //Declare method to update form fields
    public void Update_Frm_Fld(HttpServletResponse response)
         throws ServletException, IOException{
              PrintWriter out=response.getWriter();
              out.println("<SCRIPT LANGUAGE='JavaScript'>");
              out.println("document.mainform.tota.value = "+1);
              out.println("document.mainform.tota.focus()");
              out.println("</SCRIPT>");
    %>and when you call the function use this:
    <%Update(response);%>

  • Out.println() problems with large amount of data in jsp page

    I have this kind of code in my jsp page:
    out.clearBuffer();
    out.println(myText); // size of myText is about 300 kbThe problem is that I manage to print the whole text only sometimes. Very often happens such that the receiving page gets only the first 40 kb and then the printing stops.
    I have made such tests that I split the myText to smaller parts and out.print() them one by one:
    Vector texts = splitTextToSmallerParts(myText);
    for(int i = 0; i < texts.size(); i++) {
      out.print(text.get(i));
      out.flush();
    }This produces the same kind of result. Sometimes all parts are printed but mostly only the first parts.
    I have tried to increase the buffer size but neither that makes the printing reliable. Also I have tried with autoFlush="false" so that I flush before the buffer size gets overflowed; again same result, sometimes works sometimes don't.
    Originally I use such a system where Visual Basic in Excel calls a jsp page. However, I don't think that this matters since the same problems occur if I use a browser.
    If anyone knows something about problems with large jsp pages, I would appreciate that.

    Well, there are many ways you could do this, but it depends on what you are looking for.
    For instance, generating an Excel Spreadsheet could be quite easy:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    public class TableTest extends HttpServlet{
         public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
              response.setContentType("application/xls");
              PrintWriter out = new PrintWriter(response.getOutputStream());
                    out.println("Col1\tCol2\tCol3\tCol4");
                    out.println("1\t2\t3\t4");
                    out.println("3\t1\t5\t7");
                    out.println("2\t9\t3\t3");
              out.flush();
              out.close();
    }Just try this simple code, it works just fine... I used the same approach to generate a report of 30000 rows and 40 cols (more or less 5MB), so it should do the job for you.
    Regards

  • Functionality of System.out.println()

    Hello,
    can some one please explain me what happens
    an System.out.println(); is called
    for example when we are pass an Object reference of some class
    it prints the address
    what functionality is taking place internally.
    which methods are called.

    You can look for yourself. The source code for the classes in the core API is in src.zip in the JDK download.

  • Out.println in jsp?

    Can out.println be used in JSP? I got the following error:
    I have googled that out.println cannot be used in a method declaration, which is what i've done. So what do i do from there?
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:39: cannot find symbol
    symbol  : variable out
    location: class org.apache.jsp.menu_005ftest_jsp
                            out.println("<li><a href=" + strMenuLink + ">" + strMenuName + "</a>");
                            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:40: cannot find symbol
    symbol  : variable out
    location: class org.apache.jsp.menu_005ftest_jsp
                            out.println("<ul>");
                            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:42: cannot find symbol
    symbol  : variable out
    location: class org.apache.jsp.menu_005ftest_jsp
                            out.println("</ul>");
                            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:44: cannot find symbol
    symbol  : variable out
    location: class org.apache.jsp.menu_005ftest_jsp
                            out.println("<li><a href=" + strMenuLink + ">" + strMenuName + "</a></li>");
                            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:113: out is already defined in _jspService(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
                        PrintWriter out = response.getWriter();
                                    ^
    5 errors
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\nbproject\build-impl.xml:364: The following error occurred while executing this line:
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\nbproject\build-impl.xml:149: Compile failed; see the compiler error output for details.
    BUILD FAILED (total time: 1 second)At first i didnt declare a PrintWriter but then after i first got the error, i just threw it in. But it seems that even that part has an error too. Thanks.

    Thanks! I actually thought that it was not a good idea to use it because the method i created can calls itself and it is very confusing to me. So i switched back to using normal codes html. (is it called template code?) Anyway this is a new problem that i face, should i start a new thread since its a different issue?
    The new error, could it be due to the two different try and catch? (see code below)
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:40: illegal start of expression
      private static java.util.List _jspx_dependants;
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:27: 'try' without 'catch' or 'finally'
                try{
                ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:123: 'catch' without 'try'
                            } catch (SQLException ex) {
                              ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:60: 'try' without 'catch' or 'finally'
        try {
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:152: 'else' without 'if'
                        } else {
                          ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:156: class or interface expected
            }catch (SQLException e){
            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:158: class or interface expected
            }finally{
            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:160: class or interface expected
            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:162: class or interface expected
            ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:165: class or interface expected
          out.write("    </body>\n");
          ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:166: class or interface expected
          out.write("</html>");
          ^
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:167: class or interface expected
        } catch (Throwable t) {
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:170: class or interface expected
            if (out != null && out.getBufferSize() != 0)
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:172: class or interface expected
            if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:173: class or interface expected
    C:\Documents and Settings\USER\Desktop\FOS_Menu\FOS_Menu\build\generated\src\org\apache\jsp\menu_005ftest_jsp.java:176: class or interface expected
    16 errorsAnd the code for your reference:
    <%@page contentType="text/html"%>
    <%@page pageEncoding="UTF-8"%>
    <%@page import="FOS.dbconnection.*, FOS.User.*, FOS.Menu.*, javax.servlet.http.*, javax.servlet.jsp.*,javax.servlet.*,
    java.sql.*,java.awt.*,java.net.*,java.io.*;"%>
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-AU">
        <head>
            <title>FOS Menu</title>
            <script type="text/javascript" src="mb.js"></script>
            <link rel="stylesheet" href="mb.css" />
        </head>
        <body onload="mbSet('mb2', 'mbh');">
            <div id="c">
                <div id="eg">
                    <ul id="mb2">
                        <%
                        Connection conn = null;
                        Statement stmt;
                        ResultSet rs;
                        String sqlStr;
                        conn = DBConnection.getConnection();
                        try {
                            sqlStr = "SELECT menu_id, menu_name FROM application_mstr WHERE menu_type ='P' AND parent_id='N' ORDER BY module_seq";
                            stmt = conn.createStatement();
                            rs = stmt.executeQuery(sqlStr);
                            while (rs.next()) {
                                String strParentMenuId = rs.getString("menu_id");
                                String strParentMenuName = rs.getString("menu_name");
                        %>
                        <li><a href=""><%= strParentMenuName %></a>
                            <ul>
                                <%
                                getChildren(strParentMenuId);
                                %>
                            </ul>
                        </li>
                        %>                   
                    </ul>
                </div>
            </div>
            <%
                            } catch (SQLException ex) {
                                out.println("<P>" + "Error:");
                                out.println("<PRE>" + ex + "</PRE> \n <P>");
                            } catch (Exception e) {
                                out.println("<P>" + "Error:");
                                out.println("<PRE>" + e + "</PRE> \n <P>");
                            } finally {
                                DBConnection.closeConnection(conn);
            %>
            <%!
            String getChildren(String strMenu_id){
                Connection conn = null;
                PreparedStatement pstmt;
                ResultSet prs;
                String sqlStr;
                try{
                    sqlStr = "SELECT menu_id, menu_name, menu_link FROM application_mstr WHERE parent_id=? ORDER BY menu_seq";
                    pstmt = DBConnection.getPreparedStatement(conn, sqlStr);
                    pstmt.setString(1, strMenu_id);
                    prs = pstmt.executeQuery();
                    while (prs.next()){
                        String strMenuId = prs.getString("menu_id");
                        String strMenuName = prs.getString("menu_name");
                        String strMenuType = prs.getString("menu_type");
                        String strMenuLink = prs.getString("menu_link");
                        if (strMenuType == "P"){                       
            %>
            <li><a href='<%=strMenuLink %>'> <%=strMenuName %></a>
            <ul>
                <%
                getChildren(strMenuId);
                %>
            </ul>
            <%
                        } else {
                            out.println("<li><a href=" + strMenuLink + ">" + strMenuName + "</a></li>");
            }catch (SQLException e){
                System.err.println("Error executing stmt :" + e);
            }finally{
                DBConnection.closeConnection(conn);
            return "";
            %>
        </body>
    </html>

  • Intercepting System.exit() and System.out.println() calls

    hi there,
    I have often problems when working with code that uses System.exit() and System.out.println() extensively, because it becomes difficult to debug.
    Basically I do have wrappers for System.exit() (my own static exit function) and for System.out.println() (log4j).
    Still not all programmers are using these methods; Probably the only way to enforce this is some kind of code warrior, but I was hoping to be able to intercept the two System.XXX calls (and throw an appropriate Exception). is this possible ??

    Why not simply make your own security manager andhandle checkExit() and checkWrite?
    Does anyone have a simple example of this? Please?System.exit() can be intercepted using a security manager, but not System.out.xxx.
    Here is a short example:
    //set your security manager
    static{
         SecurityManager s = new OwnSecurityManager();
         System.setSecurityManager(s);
    //redirect the out stream
    try{
         PrintStream ps = new PrintStream(new FileOutputStream("output.txt"));
         System.setOut(ps);
    }catch(IOException ioe){
         ioe.printStackTrace();
    //some tests
    System.out.println("Test");
    System.exit(2);
    //your security manager
    class OwnSecurityManager extends SecurityManager{
         public void checkExit(int code){
           if(code > 0){
             super.checkExit(code);
             throw new SecurityException("Not allowed here->" + code);
         public void checkRead(FileDescriptor fd){
         public void checkRead(String file){
         public void checkRead(String file, Object context){
         public void checkPermission(Permission perm){
           if(perm.getName().equals("exitVM")){
             System.out.println("exitVM");
    }

  • Is there a way to force System.out.println to run when called

    I working on my first threaded program and having a hard time debugging. I've used System.out.println to let me know what's going on but due (I assume) to the nature of threads the output is not sequential. Is there a way to force println to execute immediatly so that they show up in the order they were called?
    Thanks --- Mike

    mjs1138 wrote:
    endasil, Thanks for the reply. I'm currenlty running the program from within the NetBeans IDE. It is the output displayed by in NetBeans "output" that I'm looking at.
    --- MikeI don't use Netbeans, but I would guess that it too pipes Standard Out and Standard Error to the same console. You didn't address my comment. Are you printing to System.err as well? This happens implicitly if you use Exception.printStackTrace(), for example.

  • Syntax to pass parameter value to jsp using href in out.println

    Hi,
    I have the URL in the form as mentioned below:
    <a href="b2c/marketing/showDocDetail.jsp"> <%=doc_no%></a>
    I've created the hyperlink using href tag to the document number in the jsp using the below syntax.
    <% String a1 = "Document ";
           String a2 = "<a href=\"";
           String a3 = "marketing/showDocDetail.jsp\">";
           String a4 = doc_no;
           String a5 = "</a>";
    out.println(a1a2a3a4a5);
    %>
    When clicked the doc_no is passed to backend RFC and export parameter is retrieved to result.jsp where values along with doc_no are displayed.
    the value after clicked is not being passed to action.java class that does the retreival.
    Needful, backend class, bom, entry in config.xml is all maintained.
    Please help me out with the syntax to pass the parameter value into java class

    Hi Bharathi,
    try below.
    <%
           String a1 = "Document ";
           String a2 = "<a href=\"";
           String a3 = "marketing/showDocDetail.do?docNo=";
           String a4 = doc_no;
           String a5 = " \">";
           String a6 = doc_no;
           String a7 = "</a>";
    out.println(a1+a2+a3+a4+a5+a6+a7);
    %>
    I assume doc_no is java variable contains value of document number
    Now create action entry in config.xml file. Suppose "actionDoc.java" class process it.
    <action path="/marketing/showDocDetail" type="com.xyz.actions.actionDoc">
                   <forward name="success" path="/marketing/showDocDetail.jsp"/>
                   <forward name="error" path="/marketing/showDocDetail.jsp"/>
    </action>
    We are passing parameter docNo=doc_no to action class actionDoc.java in this class you can retrieve request parameter docNo from request object and then process it as you want.
    Let me know if you face any problem or error.
    eCommerce Developer
    Edited by: Ecommerce Developer on Nov 9, 2009 8:35 AM

Maybe you are looking for