Printing to java console from servlets

Hi
i would like to use the java console on the browser to display some debugging output from my servlets.
using "System.out.println" would output to the server logs.
is there any way to do this??
-Eli-

I know that there is a Jakarta TLD that does this, it's one of the Tomcat4.0.1 examples.
<%@ taglib uri="http://java.apache.org/tomcat/examples-taglib" prefix="eg" %>
<eg:log>
Did you see me on the stderr window?
</eg:log>
<eg:log toBrowser="true">
Did you see me on the browser window as well?
</eg:log>Any visitor hitting the web site will not see the <eg:log> tags, however with the toBrowser="true" they will as well as you should see them on the console. Double check the TLDs on jakarta.apache.org to see what you can find. If you are using another Java Servlet container it's probably just a matter of changing a class file for the same functionality.

Similar Messages

  • Runing java pogram from Servlet

    Hi everbody
    I was trying to execute and run a java program from servlet. It seems to me the servlet can compile the code but it is not capable to execute it. I have tried to save the class file in a bat file after the servlet compiled it but it did not work. any help will be appreciated.
    try{
    String[] command = {"javac","c:\\class\\test.java"};
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(command);
    catch(Exception ex){ }
    try{
    String[] command = {"java","c:\\class\\test"};
    Runtime rt = Runtime.getRuntime();
    Process p = rt.exec(command);
    catch(Exception ex){ }

    Don't cross-post your questions, please.

  • Calling Java application from servlet

    Hi !
    I'm trying to run a Java application from within a servlet with Tomcat 4. I'm using the Runtime.getRuntime ().exec () method. So the application is run in a different JVM as a subprocess of the servlet. I use ObjectInputStream and ObjectOutputStream and a serializable object to enable communication between the servlet and the application.
    I tested the application and the serializable object with another Java application that works as the caller and it works fine. However, replacing the caller application with the servlet I get a StreamCorruptedException. The structure of the caller application and the servlet is the same.
    My questions are:
    - Is there something I should configure in Tomcat to create a subprocess ?
    - What is the cause of the StreamCorruptedException ? How do I get it with the servlet and not with the application ?
    - Should I use an environment with the call to Runtime.getRuntime ().exec () ? How do I use it ?
    - Is the called application forced to run in my servlet's context ?
    - Is there a better way to do this ?
    Thanks to all

    Here's my code:
    1. The serializable object:
    // Object Obj
    import java.io.*;
    public class Obj implements Serializable
    public int n;
    public Obj ()
    n = 0;
    public Obj (int n)
    this.n = n;
    public String toString ()
    return getClass ().getName () + " -> (n = " + n + ")";
    2. The application Sub (subprogram)
    // Application Sub
    import java.io.*;
    public class Sub
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, InterruptedException, ClassNotFoundException
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj;
    ois = new ObjectInputStream (System.in);
    obj = (Obj) ois.readObject ();
    f = new File ("Sub.txt");
    fw = new FileWriter (f);
    fw.write (obj.toString ());
    fw.close ();
    oos = new ObjectOutputStream (System.out);
    oos.writeObject (obj);
    ois.close ();
    oos.close ();
    3. The application AMain (caller application)
    // Application AMain
    import java.io.*;
    class AMain
    private static File f;
    private static FileWriter fw;
    public static void main (String [] args)
    throws IOException, ClassNotFoundException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    r = Runtime.getRuntime ();
    p = r.exec ("java Sub");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    B.comunica (obj);
    System.out.println ("AMain sends to Sub: " + obj.toString ());
    try
    p.waitFor ();
    catch (InterruptedException e)
    System.out.println ("Subprogram was interrupted");
    System.out.println (e.toString ());
    ois = new ObjectInputStream (p.getInputStream ());
    System.out.print ("Sub sends to AMain: ");
    obj2 = (Obj) ois.readObject ();
    System.out.println (" " + obj2.toString ());
    oos.close ();
    ois.close ();
    p.destroy ();
    4. The servlet SMain (the calling servlet)
    // Servlet SMain
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    import java.io.*;
    import java.util.*;
    public class SMain extends HttpServlet
    public void doPost (HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    Runtime r;
    Process p;
    ObjectInputStream ois;
    ObjectOutputStream oos;
    Obj obj, obj2;
    int state, i;
    res.setContentType ("text/html");
    ServletOutputStream out = res.getOutputStream ();
    out.println ("<html>");
    out.println ("<head><title>Sub</title></head>");
    out.println ("<body>");
    out.println ("Invoking subprogram...");
    out.println ("<br>");
    try
    r = Runtime.getRuntime();
    p = r.exec ("java -cp .;c:\\Programs\\Apache~1.0\\webapps\\SMain\\WEB-INF\\classes Sub");
    out.println ("...invoked<br>");
    oos = new ObjectOutputStream (p.getOutputStream ());
    obj = new Obj (5);
    oos.writeObject (obj);
    oos.flush ();
    out.println ("<br>SMain sends to Sub: " + obj.toString () + "<br>");
    try
    p.waitFor ();
    catch (InterruptedException e)
    out.println ("<br>Subprogram was interrupted<br>");
    out.println ("<br>" + e.toString () + "<br>");
    state = p.exitValue ();
    out.println ("<br>Subprogram state: " + state + "<br>");
    ois = new ObjectInputStream (p.getInputStream ());
    out.print ("<br>Sub sends to SMain: ");
    obj2 = (Obj) ois.readObject ();
    p.destroy ();
    catch (SecurityException e)
    out.println ("<br>SecurityException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (IOException e)
    out.println ("<br>IOException<br>");
    out.println ("<br>" + e.toString () + "<br>");
    catch (Exception e)
    out.println ("<br>Exception<br>");
    out.println ("<br>" + e.toString () + "<br>");
    out.println ("</body>");
    out.println ("</html>");
    So, as you can see, both application AMain and servlet SMain invoke application Sub and pass it the serializable object Obj. Oddly enough, application AMain works fine whereas servlet SMain throws a StreamCorruptedException exception.
    johnpoole said:
    �It's hard to guess what would cause the exception without seeing code, but the interaction between the processes would differ from that between two applications, because the servlet process is started with a different class loader. I'm not sure which one the jvm started by the call would use.�
    How can I enforce that a System classloader be used in the call to Runtime.getRuntime ().exec () ? (I mean by System classloader a classloader equals to the one applications are launched from console).
    johnpoole said
    �Is there a reason why you aren't starting the second process manually and then connecting to it on a port?�
    The idea is providing a Web interface for an application running in the server. The servlet is used to restrict access to this application but once access is granted (passing the servlet) the application should not be constrained.

  • Java console from IE

    I enable the Java Console in the "Internet Options" from my IE Browser. And i can see it in my View Option. But when click on the option, it doesn't show up! Could u tell me why?
    Thanks,
    Bick

    Should do. You may need to restart your computer after setting the option.

  • I cannot bring up the Java console from IE in WindowsXp

    Hi Team,
    My System contains Windows Xp as a operating System.
    My IE is unable to dispaly the applet's.Although my IE tells me that I have JRE running (under IE / Tools / Internet Options / Advanced), I cannot bring up the Java console also.
    I Checked in Control Panel/Java/show-console is activated. But i am unable to bring up the java console.
    Thanks
    T. Shankar Reddy

    I got the solution. Now my application is runnig successfuly.
    The problem is with J2SDK installation. I un-installed j2sdk1.4.2.08 and again I installed. then it is working properly.
    Thanks
    Shankar Reddy

  • Is it possible to call a java method from servlet

    Hi All,
    I am trying to import a java class to my servlet and call a method of that class, is this possible. I am getting an error while importing the class.
    I am using tomcat, have put my class files in th path
    \WEB-INF\classes\com\kiran
    My java goes like this
    package com.kiran;
    import java.sql.*;
    import javax.sql.*;
    public class DbCon
    { Connection con=null;
    public Connection getCon()
    -----return con;
    catch(Exception e){ return con; }
    and my aim is to call getCon() from my servlet. which is as follows
    package com.kiran;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import com.kiran.DbCon;
    public class check extends HttpServlet
    DbCon db;
    i am not able to compile my servlet, err is --> cannot find symbol DbCon..
    How can i import the class, do i require any entries in web.xml ?
    expecting your advice..
    Thanks in advance
    Best Regards,
    Kiran

    Ok, first off, if you are testing in tomcat (and as you said you are placing the class files in the path), you already compiled this classes, right? Otherwise I don't see how you placed your classes in /WEB-INF/classes/. Note that you will need two class files (based on your code. If not, then I'm missing part of the question. Typically, your IDE will help you with this problem a lot. The only thing that seems confusing is the catch (Exception e) statement which needs to be as part of a method (I assume this is a typo on your part).
    If your problem is at runtime, don't forget to configure your web.xml to see your servlet.

  • Java.lang.SecurityException when trying to execute Workflow-Java-API from Servlet

    I'm trying to call some of the Oracle Workflow-Java-API Classes/Methods from a servlet running on OC4J.
    The following Code-Sample is exactly copied from the WFTest Example shipped with Oracle-Workflow:
    wfDB = new WFDB(user, ident, "jdbc:oracle:thin:@", "host:1521:tnsstring");
    String charset = System.getProperty("CHARSET");
    if (charset == null) {
    charset = "UTF8";
    ctx = new WFContext(wfDB, charset);
    if (ctx.getDB().getConnection() == null) {
    throw new Exception ("Keine Verbindung zum Workflow");
    On OC4J integrated in JDeveloper everything works fine when i run my test-servlet with this code.
    On 9ias with OC4J running on a SuSE-Linux Server i get the following Error:
    java.lang.SecurityException: class "oracle.apps.fnd.wf.WFContext"'s signer information does not match signer information of other classes in the same package
    at java.lang.ClassLoader.checkCerts(ClassLoader.java:554)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:482)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:106)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:243)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:51)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:190)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:183)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:294)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)
    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:310)
    at oracle.apps.fnd.wf.engine.JdbcEngineAPI._sqlQueryText(JdbcEngineAPI.java)
    at oracle.apps.fnd.wf.engine.EngineAPI.getItemTypes(EngineAPI.java)
    at WorkflowData.doGet(WorkflowData.java:61)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:195)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:309)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:336)
    at com.evermind[Oracle9iAS (1.0.2.2.1) Containers for J2EE].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:508)
    at com.evermind[Oracle9iAS (1.0.2.2.1) Containers for J2EE].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:177)
    at com.evermind[Oracle9iAS (1.0.2.2.1) Containers for J2EE].server.http.HttpRequestHandler.processRequest(HttpRequestHandler.java:576)
    at com.evermind[Oracle9iAS (1.0.2.2.1) Containers for J2EE].server.http.HttpRequestHandler.run(HttpRequestHandler.java:189)
    at com.evermind[Oracle9iAS (1.0.2.2.1) Containers for J2EE].util.ThreadPoolThread.run(ThreadPoolThread.java:62)
    As you can see, the first Workflow-API-Object (WFDB) gets correctly instantiated. But the second one crashes.
    The java.policy and java.security files are exactly identical on both machines, my PC and the Linux-Server.
    Where might be the problem ?
    How can we fix this ?
    thanks in advance for any help
    Ralf

    okay, okay,
    my/our own fault.
    To prevent anyone else of makeing the same mistake, a short decription:
    We stored the wf????.jar files inside the $JAVA_HOME/jre/lib/ext directory.
    The correct way is to let them inside $ORACLE_HOME/jlib dir of the oracle db and extend the classpath, respectively add the following lines to 'orion-application.xml' of the app.
         <library path="$ORACLE_HOME/jlib/wfapi.jar" />
         <library path="$ORACLE_HOME/jlib/wfjava.jar" />

  • Calling java application from servlet using servletexec servlets

    We are using servletexec 3.0,IIS 5.0, sun Java SDK 1.3.1_12.
    I have a servlet which works fine. This servlet is being called from the submit of the form in a html file.
    It works fine.
    But now i have to use a third party credit card application from my servlet.How can i do that.
    I have added the third party jar files in the classpath of servletexec.
    How can i use their methods.
    Please let me know.

    Something like this ?
    import thirdparty.*;
    import javax.servlet.http.*;
    public class MyServlet extends HttpServlet {
      public void doGet(HttpServletRequest request, HttpServletResponse response) {
        ThirdPartyClass t = new ThirdPartyClass();
        t.someMethod();
    }

  • Forwarding requests on to non-java pages from servlet.

    I have designed a web application using a form of single controller pattern.
    I have a number of JSPs.
    Each of these JSP's has a form element which if submitted got to a single servlet (Controller)which then forwards on the request to a different class based on the paramter passed. For example this form would call the SubmitFeedback class.
    <form name="feedbackform" method="post" action="<%=request.getContextPath()%>/controller">
    <input type="hidden" name="action" value="SubmitFeedback"/>
    <input type="hidden" name="page"   value="feedback.jsp">
    <tr><td><input type="submit" name="go" value="Go"/></td></tr>
    </table>
    </form>After the class has done its processing it returns what page to go next to the Controller class and this forwards the request on. to the next jsp
    String nextPage = createAction(request.getParameter(PARAM_ACTION)).handleRequest(this,request, response, request.getParameter(PARAM_PAGE));          
    request.getRequestDispatcher(nextPage).forward(request, response);
    return;This is all fine but now I have a sitation where after the user submits the form I want do some processing then forward them onto another page which is not part of my system, nor java. But the RequestDispatcher is only for the current Context within a Servlet Container.
    Could someone explain how I do this, what am Im missing please.

    i am not a JavaScript expert, so I can't be sure this is everything, but:
    1) The javascript has to be put inside a <script></script> block (you also had an extra close bracket):
    <script type="text/javascript">
      <!--
      function validateAccept() {
        toReturn=true;
        if (form.accept.checked==false) {
          alert("You must select at least one checkbox to search");
          toReturn=false;
        return toReturn;
      //-->
    </script>The script block is usually put in the head section also, but that is not necessary.
    2) I would call this function from the onsubit event of the form rather than the onclick of the submit button
    <form  name="form" action="..." method="post" onsubmit="return validateAccept();">
      //...3) You will need to identify the form that you want to use inside the function. Just using the name form won't work, it has to be retrieved from a certain context. The easiest thing is to pass it in as a parameter:
    <script type="text/javascript">
      <!--
      function validateAccept(form) {
    <form  name="form" action="..." method="post" onsubmit="return validateAccept(this);">

  • Problems printing html page created from servlet

    Hi
    How do I go about to print a html page that spans outside the visible window (to the left). All I get when I print is the visible page.
    Is it at all possible?
    Would appreciate an answer.
    Thanks
    David Mossberg

    No, not impossible to do.
    You need to provide a printer friendly version of the content so that it spans correctly.
    Again, this is not a Java problem this is an Application problem.
    How you format the data is down to you.

  • How to print on console from applet for debugging purpose.. ?

    Hi,
    To debug my app which is an applet running in browser, I inserted some sysout statements in applet but it do not work.
    Is it not possible to sysout with applet or there is any other way for debugging.
    Please reply..
    Thank you.

    To debug my app which is an applet running in browser, I inserted some sysout statements in applet but it do not work.The sysout statements prints to 'Java console', you can see it in browser by selecting 'Show Java Console' somewhere in the menus of browser.
    Or you can make it to appear every time applet is loaded. This can be done from the Java Control Panel.
    ControlPanel>Java>Advanced>JavaConsole>ShowConsole
    Also, for complete debugging check all the boxes in:
    ControlPanel>Java>Advanced>Debugging
    Thanks!

  • Is it possible to open the Java plugin / WebStart Console from my app ?

    Hi,
    I would like to know if it is possible to add a menuitem to my application that would start the Java plugin/web start console.
    That would be nice when people have errors in my application.
    Martin

    Thanks for the information, but is there a way to do it without using exec methods ?
    I just want to bring up the Java Console from my app, in the more portable way possible ;-)
    Martin

  • How many versions of java console do I need in extensions?

    In extensions I have java consoles from 6.0.11 to 6.0.24. Can I remove the old old ones? Mike

    You do not need any of them. They are not needed to run Java applets.
    See:
    * http://kb.mozillazine.org/Java#Multiple_Java_Console_extensions

  • Sun Java Console & Applets don't display properly on JRE 1.5.0_05

    Duplicate Post as it was equally relavant to this forum: [http://forum.java.sun.com/thread.jspa?threadID=666689&tstart=0 ]
    Hi,
    We have a signed applet based application hosted on weblogic server. We are trying to launch the application on IE 6.0, JRE 1.5.0_05.
    When we try to see the Sun Java Console from IE's Tools Menu bar, we don't see any text in the window and also the side bars & buttons ("clear", 'copy", "close") are not rendered properly. Now if we, try to bring the focus to text area of Sun Java Console, and try to select all (Ctrl+A), we only see some text selected, but not what it is. Now if we copy the text onto the notepad, we can see the text.
    Next, when we try to launch the signed applet based application, we get the security warning, where only we can see the dialogue box and not the text or buttons. By randomly clicking on this security dialogue, if we hit on yes, the Applet based application is launched. The UI is totally off color; either you see some widgets on application partially or totally blackened or in different colors. Application basically looks to be in chaos.
    This behavior is not observed in any of the previous JRE versions, i.e. JRE 1.5.0_04 or any previous versions. Interesting part is after uninstalling JRE 1.5.0_05, if we install 1.5.0_04; problem persists, but not in JRE 1.4.
    We have observed the same behavior on number of machines. Is it a known issue? What�s the reason & solution?
    Thanks in Advance,
    Vinayak

    When we try to see the Sun Java Console from IE's
    Tools Menu bar, we don't see any text in the window
    and also the side bars & buttons ("clear", 'copy",
    "close") are not rendered properly. I suspect you're running into graphics issues. Perhaps java5 is trying to optimize too much, and you have older or buggy Windows drivers.
    Try:
    * getting the latest graphics drivers for your hardware from your vendor and installing them.
    If that doesn't work, try
    * putting options like "-Dsun.java2d.noddraw" in the Java Control Panel as the default VM options for your Java.
    That's actually a bit aggressive - you can start with, say, "-Dsun.java2d.d3d=false" or "-Dsun.java2d.ddoffscreen=false" (each of these is less drastic than noddraw).
    Then make sure you quit all IEs, and restart one.

  • Firefox 4 on Windows Vista loads java applet for my MOO site then immediately closes Java Console, dumping me from the site, so I have had to go back to Firefox 3.6.17 which works fine

    I have 32-bit Vista Business, with Firefox as my default browser. I recently upgraded to Firefox 4 and found that I can no longer access my VRoma MOO, which uses a Java applet to connect. I can connect to the site, but within 30 seconds the Java Console closes by itself (without my having done anything) and dumps me from the MOO. Following suggestions on this website, I uninstalled two earlier versions of Java which were on my computer and downloaded Java 6.0.25, the latest version. I also disabled previous Java Console extensions in the browser. None of this helped. I can stay connected with IE, and I can stay connected with Firefox 3.6.17, which I have had to install again. This is disturbing, because VRoma has many student users and I don't want them to encounter this problem if they are using Firefox 4.

    Hello Andrew.
    You may be having a problem with some Firefox add-on that is hindering your Firefox's normal behavior. Have you tried disabling all add-ons (just to check), to see if Firefox goes back to normal?
    Whenever you have a problem with Firefox, whatever it is, you should make sure it's not coming from one of your installed add-ons, be it an extension, a theme or a plugin. To do that easily and cleanly, run Firefox in [http://support.mozilla.com/en-US/kb/Safe+Mode safe mode] and select ''Disable all add-ons''. If the problem disappears, you know it's from an add-on. Disable them all in normal mode, and enable them one at a time until you find the source of the problem. See [http://support.mozilla.com/en-US/kb/Troubleshooting+extensions+and+themes this article] for information about troubleshooting extensions and theme. You can troubleshoot plugins the same way.
    If you want support for one of your add-ons, you'll need to contact its author.

Maybe you are looking for