ClassCastException in webapp, but OK from console

Teaching myself webapps.
Using Tomcat, I am writing a webapp for the small private school where my wife works. It manages the assignment of students to the rotating schedule of art periods during the day, always done by hand up till now (maddening).
One of the things I want to be able to do is not just display database info in the browser, I also want an option for the user to write certain things out to a file and then be able to get the file and print it, like a listing of the current classes and the students assigned. Printing off a web page is not very satisfactory.
I found how to use Java to open and write to a file, so I hope I can make that work. I wrote a simple test class to play with it, and it works from a command line. It creates the file and writes to it just fine. I was delighted.
import java.io.*;
public class OutWrite
     public static void write()
          try
               PrintWriter out = new PrintWriter(
               new BufferedWriter(
               new FileWriter("c:/word.doc")) );
               out.println("This is the big test.");
               out.close();
          catch (IOException ioe)
               System.out.println("ouch");
But it throws a ClassCastException when I tried to add it into the app. I just added it into the init() of one of the first servlets that's called
public void init()
     OutWrite.write();
When I click the button that calls that servlet, it now throws the exception:
java.lang.ClassCastException: OutWrite
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:903)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:668)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:416)
at org.apache.catalina.servlets.InvokerServlet.doGet(InvokerServlet.java:180)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:740)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:171)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:594)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:392)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:565)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:619)
at java.lang.Thread.run(Thread.java:536)
I hope this is a "rookie" situation where there's just some piece of the puzzle that I don't know about.
Thanks

shok 411:
Yes, I have it in WEB-INF/classes, thanks. That was a learning hurdle I jumped over (with help on this forum) a month ago ....
And I did it first the way you suggested, and then tried it again as a static call.
But I found the problem now -- I'm such a dope. I do this stuff by groping around in the dark, reading online tutorials, buying books, trying things and throwing them out. And I often lose track of what I do.
10 minutes earlier I had tried to just get the button in the app to directly call the OutWrite class. I took the form/action call that previously pointed to an existing servlet and "temporarily" pointed it to OutWrite
<form target="worksheetframe" action="http://felecha:8080/ArtBlocks/servlet/OutWrite">
That got the exception (which I would still like to know why).
Then I thought - hey, put a call to it as just a java class called from that existing servlet already in the app, just stick it into its init() call. Well, I did that, but never went back to correct the action of the button. I just now found it, and sure enough, if the action of the button calls the existing servlet which in turn just makes a static call to OutWrite.write(), bingo! It writes to the file! (the static version works)
But now there's a new problem, and I will have to wait till I get home from work.
It will create and write to the file the first time. If I then delete the file and click the button again, it will not. It will only do it for me if I use the Tomcat Manager "reload" feature and then do it.
What can that mean???
And at some point I have to learn how I can append to the file or overwrite it.

Similar Messages

  • Executing from Console

    Hi =)
    I've just written a program with eclipse and running it from inside Eclipse works. But outside from console does not.
    flaab@Debian ~/Desarrollo/Conexion/principal\ $ java Start
    Exception in thread "main" java.lang.NoClassDefFoundError: Start (wrong name: principal/Start)
            at java.lang.ClassLoader.defineClass1(Native Method)
            at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
            at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
            at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
            at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
            at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)What might this be?

    Hi flaab,
    Just to clarify a bit, if running the program from the command line (terminal, bash, etc.), you either have to be within the directory the program was saved in; the said directory must be on your Java class path; or, you must specify the path when compiling and running the program like so:
    javac -classpath .;C:\users\dac\classes;C:\tools\java\classes ...(which I 'stole' from http://manticore.2y.net/doc/jdk1.1.8/docs/tooldocs/win32/javac.html)
    Setting the path is OS specific, so take a look at Google and you should be able to set it up pretty quickly. That is, assuming that's what you want.
    Kevin

  • ALSB 3.0 : Request message works in Test Console but not from Client side

    By invoking a Web Service operation through a signature/encryption enabled Proxy Service in the ALSB Test Console for Proxy Services, i get a successful response.
    Now when invoking the operation from a client application i get the following error response:
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
    <env:Fault xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <faultcode>wsse:FailedCheck</faultcode>
    <faultstring>weblogic.xml.crypto.encrypt.api.XMLEncryptionException: Unable to resolve encryption key for weblogic.xml.crypto.encrypt.api.EncryptedType{keyInfo=null, cipherData=CipherValue: zDeM4MKI8OeFzgJAR+z16ZE3cUfw54DtMKojPNACkVVZM0hazes+DcI4rJIHWzgt5N259pi9WTKgSEgBxQLZ3qD6PycrwTZuQ/4g2JbBwLwbO9WS40NsIhZRQCtguFPG8vKwNWeoXMOZ5w0m3jhV2ahFWZCTAipoG4XIOv/7pEw=, id='Enc-6abda982-1678-4774-97f3-cada98d32869', mimeType='null', encoding='null', encryptionMethod=EncryptionMethod: algorithm = http://www.w3.org/2001/04/xmlenc#aes256-cbc;}</faultstring>
    </env:Fault>
    </env:Body>
    </env:Envelope>
    Even when pasting the original request from the Test Console in ALSB into "soapUI" and executing the request it does not work:
    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
    <env:Header/>
    <env:Body>
    <env:Fault xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
    <faultcode>wsse:InvalidSecurity</faultcode>
    <faultstring>Could not validate encryption against any of the supported token types</faultstring>
    </env:Fault>
    </env:Body>
    </env:Envelope>
    So what's behind all this? Why does it work in the test console but never from other points.

    In both ways, with Direct Call option selected or deselected, the behaviour is the same.
    I cannot explain, why the replay of the request does not work from outside the Service Bus. Is there some sort of unique data mixed into the CipherValue data or something like that?

  • Code source works fine from console application but not from SharePoint interface

    Hi;
    Please can you help
    me to understand why my code below works fine from console application (VS 2010) and not working from interface of my SharePoint collection site :
    From console application : the subsite is created and I can to open without any problem
    From Sharepoint GUI : the subsite is created but impossible
    to open subsite : error 404 page not found ?
    The subsite creation is very long (2 minutes) and in concole application When I try to open the subsite just after its creation I have page not found and I must waits (several refresh) more time to open the subsite correctly.
    Can be I must to display a PoPup to show the progress creation ?
    using System;
    using System.Security.Permissions;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Security;
    using Microsoft.SharePoint.Utilities;
    using Microsoft.SharePoint.Workflow;
    namespace CreateSubSiteClients.EventReceiver1
        public class EventReceiver1 : SPItemEventReceiver
            public override void ItemAdded(SPItemEventProperties properties)
                     base.ItemAdded(properties);
                     try
                         SPWeb web = properties.OpenWeb();
                         if (properties.List.Title == "REFCLIENTS")
                             SPListItem curItem = properties.ListItem;
                             string name = properties.ListItem["SITE"].ToString();
                             curItem["SiteUrl"] = web.Url + "/" + name;
                             SPWeb rootWeb = web.Site.RootWeb;
                             SPWebTemplateCollection webTemplates = rootWeb.GetAvailableWebTemplates(1036);
                             SPWebTemplate webTemplate = null;
                             String webTemplateName = "ModeleSiteCourrier";
                             String webTemplateSearchName = "";
                             for (int i = 0; i < webTemplates.Count; i++)
                                 webTemplateSearchName = webTemplates[i].Name.ToString();
                                 if (webTemplateSearchName.Contains(webTemplateName))
                                     webTemplate = webTemplates[webTemplateSearchName];
                                     break;
                           SPWeb newSite = web.Webs.Add(name, name, name, Convert.ToUInt16(1036), webTemplate, false, false);
                            newSite.Navigation.UseShared = true;
                            newSite.Update();
                            newSite.Close();
                            Console.WriteLine("Le site suivant a été crée", name);
                     catch (Exception ex)
                         properties.Status = SPEventReceiverStatus.CancelWithError;
                         properties.ErrorMessage = ex.Message.ToString();
                         properties.Cancel = true;
    Regards

    Hi,
    To create subsite using event receiver in SharePoint Empty Project, you can refer to:
    Sharepoint 2010 event handler to create subsites
    To display a PoPup to show the progress creation, you can use:  MessageBox.Show("Hello, world.");
    More information:
    MessageBox.Show Method (String)
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Listener actually up as seen from backend but from console gets error

    Hi
    My SCAN listener is shown running from backend but is shown down from console.
    response for listener shows below error.
    Any suggestions/hints
    Thanks
    LSNRCTL for Linux: Version 11.2.0.2.0 - Production on 06-JUNE-2011 11:44:54 Copyright (c) 1991, 2010, Oracle. All rights reserved. Welcome to LSNRCTL, type "help" for information. LSNRCTL> Connecting to (DESCRIPTION=(ADDRESS=(PROTOCOL=IPC)(KEY=LISTENER_SCAN1))) TNS-12541: TNS:no listener TNS-12560: TNS:protocol adapter error TNS-00511: No listener Linux Error: 2: No such file or directory LSNRCTL>

    Thank you for your help.
    I am using a RAC database and this is the status
    srvctl status scan_listenerSCAN Listener LISTENER_SCAN1 is enabled
    SCAN listener LISTENER_SCAN1 is running on node oradb123
    SCAN Listener LISTENER_SCAN2 is enabled
    SCAN listener LISTENER_SCAN2 is running on node oradb124
    SCAN Listener LISTENER_SCAN3 is enabled
    SCAN listener LISTENER_SCAN3 is running on node oradb124
    srvctl config scan_listenerSCAN Listener LISTENER_SCAN1 exists. Port: TCP:1730
    SCAN Listener LISTENER_SCAN2 exists. Port: TCP:1730
    SCAN Listener LISTENER_SCAN3 exists. Port: TCP:1730
    [ oradb469:/home/oracle ]
    srvctl config scanSCAN name: oemcrsp-xyz.net, Network:
    1/10.180.5.0/255.255.255.0/eth0
    SCAN VIP name: scan1, IP: /oemcrsp-xyz.net/10.180.5.186
    SCAN VIP name: scan2, IP: /oemcrsp-xyz.net/10.180.5.187
    SCAN VIP name: scan3, IP: /oemcrsp-xyz.net/10.180.5.185

  • Problem with getting unicode values from console

    Hi,
    In my application I am passing unicode value like \u00DF from console. and writing this string value to a utf8 file. But in the file the value is printed not the actual unicode character.
    Where the things are getting wrong.
    I have declared a string in java like ;
    String abc = "\u00DF";
    and printed this to a utf8 file, it works fine and the corresponding unicode character for \u00DF is printed.
    Why the unicode value passes from console is not working property. How can i resolve this ?
    Thanks in advance...
    <!--Session data-->

    And how are you putting it into the console in the first place?

  • How to create a .par file from console apart from tools like eclipse,studio

    Plz reply me if any body knows how to create .par file from Console i.e command prompt.just like creation of .jar & .war file in java.I have created some iViews and making .par files from tool Eclipse/Netweave rstudio etc..I waqnt to create from console..How it is possible?
    Regards
    Sridhar Raju

    Hi Sridhar,
    I'm unsure for what you'd need this, but in general there are at least two possibilities:
    - manually pack everything into the dir structure needed (documented here: http://help.sap.com/saphelp_nw04/helpdata/en/f9/561140d72dc442e10000000a1550b0/frameset.htm ), than create a ZIP with some command line tool (e.g. JAR), naming it to .par.
    - use ANT to do this; with this, you can even deploy the file, see PAR-File deployment with ANT (EP6)
    Hope it helps
    Detlev

  • Read Input from console !!!

    Im am very new to java and trying to learn java ..
    Now the problem i have is, I have to read input from console without using the BufferReader method..
    Please tell me how to go about it..
    I have a assignment to complete and im not able to figure out the way out.
    Help ..

    http://java.sun.com/j2se/1.4.1/docs/api/java/lang/System.html
    Read first about the System class provided by Java.
    Select the 'in' method of System class and it will take
    you to the InputStream.
    http://java.sun.com/j2se/1.4.1/docs/api/java/io/InputStream.html
    An essay way of reading input is:
    "value?"=System.in.read();
    Try and see if this works. It will not use the
    BufferReader portion, but it gives you another way
    of reading from the console.

  • Read characters from console.

    Hii
    I'm trying for 2 days to read characters from console on the fly, but it didn't work.
    I want to read each char that user press on line and without waiting for the Enter button. It's like an keyboard event but there is no GUI.
    I will appreciate any help.
    Thanks.

    I don't understund what you really want to do.it is possible mesure the time between each char type using the last code :
    char charPressed='\0';
    String line="";
    while(charPressed != '\n')
    try
    // start time
    charPressed =(char) System.in.read();
    line += charPressed;
    // end time
    // want to get out
    if(...) break;
    catch(IOException ioex) {ioex.printStackTrace();}
    Sorry, but your code doesn't measure the time between each char type.
    The function read waits for the "enter" key, and just after pressing enter your code will start to read all the chars you typed before "enter", so it won't do it.
    Read function will not help in this subject.

  • Tomboy, do not open properly... just from console

    Hi!
    I have installed tomboy http://www.gnome.org/projects/tomboy/ using pacman...
    But the problem is that the only way to open it is from console...
    the button on kde just do nothing... how can I see wich is happening when I hit the button?
    because there is no error at all, just nothing...
    any idea?
    TIA, and sorry for the bad english
    luciano

    marxav... you are god!
    thanks a lot!

  • After upgrading to 10.7.5 internet is accessible from console only

    When I enter any address in the browser (Firefox, Chrome, Safari, Opera) or trying to start apple software update, it complains about network error.
    When I use IP address in the browser, it loads fine, so it seems a DNS issue to me, but from console curl works perfectly and other utils can resolve DNS also.
    $curl -I apple.com
    HTTP/1.1 302 Moved Temporarily
    Location: http://www.apple.com/
    Content-Type: text/html
    Cache-Control: private
    Connection: keep-alive
    I've also tried tried:
    $ping apple.com
    PING apple.com (17.149.160.49): 56 data bytes
    Request timed out for icmp_seq 0
    Request timed out for icmp_seq 1
    $ping google.com
    PING google.com (173.194.39.66): 56 data bytes
    64 bytes from 173.194.39.66: icmp_seq=0 ttl=57 time=37.793 ms
    I have no clue how is this possible. Any ideas?

    You're not the only one. I've been re-indexing on and off for the last four days to no avail. I had to call Apple today and was put through to a senior technical advisor. After doing a data capture for them I was told that they should be able to come back with an answer within the next two days.
    It's worth giving them a call to let them run through the clearing caches process with you if you haven't done that already. Remember that using your machine whilst it's indexing also slows the process down.
    I will let you know when they come back with an answer but I hope by t would hahen both of our machines would have finished re-indexing by then...

  • Jpublisher from console

    I have 2 schemas (a,b) in schema a ,have object Obj1.
    Using jpub with schema a I have created custom objects.
    Schema b have access to Obj1 ,so i'm trying to create custon objects using schema b also ,but it is throwing below exception.
    oracle.jpub.JPubException: J2T-116, ERROR: Type or package UFOAPP.OBJTYP_FUNDACCOUNT_LIST_A was not found in the database

    There are actually two ways to get access the console log again.  One is through Console.app and one is via terminal.
    In Console.app...
    Go to File --> New System Log Query...
    your expression should be:   [Facility] [is equal to] "com.apple.console"
    and you can can make the 'Search Name' equal to "Console Messages".
    Once you click OK, you will return the same functionality to your console.app that you had previous to 10.7.
    In Terminal...
    symply type tye following and strike return:
    syslog -C
    terminal then prints all the conosoel messages to the standard output (your screen), then exits back to the command prompt.
    If you want to clean it up and keep the console listing live (waiting for new messages to appear), type the following:
    syslog -B -C -w
    This displays yoru console log, but only messages that have ben generated since the last boot, and waits for new messages.
    strike ^C  (command+c) to exit
    For more information, you can use the manpage for syslog to better understand the tool set.
    (man syslog)
    Hope this helps.
    Just FYI the removal fo Console Messages from console.app persists through 10.9.2 (time of this writing).
    Also FYI, with the terminal method it is quite handy to monitor multiple systems (or rack full of xserves like I still have the pleasure of managing) via SSH

  • Starting desktop/windows from console?

    Is there a way to start the user interface (desktop/windows) from the console? I lost the ability to log into the account (using the login window) I have been using for quite a while. (I get returned to the login window . . .) I can log in to that account via the console. (I tried a couple of things suggested in the other posts to this discussion, but no go so far.)
    So, after logging in I tried "startx", but no go.
    Is there a command to start the desktop environment?
    Message was edited by: Timothy S Cale

    Thanks Thomas:
    I am new to Macs, so I don't know the terminology. I am also new to forums/discussions . . .
    I lost the ability to login to my account using the GUI. How that happened I don't really know. But I remember two things when looking at System Preferences for Accounts before the "fall". I had a Network Account Server that was seemingly associated with a company for which I worked in the past, and that there was a check next to "Allow Network Users to Login" (or something close to that.) I deleted the server listed, and unchecked the option to allow Network Users to Login.
    This is seemingly similar to what Brian Keefer in another recent thread (early Feb.) described . . . after he unchecked "Allow Network Users to Login".
    I can login from the console, but not from the GUI. Like him.
    (Except, I can login as root. I created a second user account, and I can login with that account.)
    I tried to follow what Brian Keefer finally recommended: use a command that I have never heard of -
    dseditgroup -o delete -T group com.apple.access_loginwindow
    To get rid of com.apple.access_loginwindow. That didn't solve the problem.
    I also used Disk Utilities from the Install Disk to repair the disk and the permissions. That didn't solve the problem.
    So, I would like to return to using my original user account. In the absence of full use, I think I can get what I need from that account into my new account if I can start the desktop environment. So naturally, from my linux experience I tried startx.
    Any help will be appreciated.

  • Can't start lxde from console

    Hi, I've managed to install lxde fine but I can't start it through console. I don't have a login manager atm...
    When I do use this command:
    startlxde
    nothing happens...:(
    Any help would be appreciated...:)
    thanks in advance

    ~/.xinitrc
    exec startlxde
    From console: startx.
    See this wiki entry.
    Enjoy,
    Bob
    Last edited by Hrod beraht (2009-02-04 21:08:23)

  • NoClassDefFoundError javax.crypto.spec.secretkeyspec from console

    Hello, I have done a program in eclipse, using the JCE to encrypt and decrypt some messages using AES. In the eclipse graphical interface it works perfect, but if i run it from console, i mean like this
    java -jar org.eclipse.osgi_3.6.0.v20100517.jar -console -configuration config_path -clean -dev file:dev.properties_path
    It works but throw the exception
    NoClassDefFoundError javax.crypto.spec.secretkeyspec
    I think there must be something wrong with the java path because JCE is already inside the jre environment. I need to know how can i indicate in the command line, the right path to the JCE
    I am working on windows
    Thank you!

    yes, i mean
    NoClassDefFoundError javax.crypto.spec.SecretKeySpec
    but i wrote it fast and i didn't realize....
    My output for java -version is
    java version "1.6.0_21"
    Java (TM) SE Runtime Environment (build 1.6.0_21-b06)
    Java HotSpot(TM) Client VM (build 17.0-b16, mixed mode, sharing)
    So i think that outside eclipse i am using the good one, then i don't know why it doesn't work. Actually, i forgot to say that in the log file, i get this exception message:
    !ENTRY org.eclipse.osgi 4 0 2010-10-15 11:35:12.273
    !MESSAGE Application error
    !STACK 1
    java.lang.IllegalStateException: Unable to acquire application service. Ensure that the org.eclipse.core.runtime bundle is resolved and started (see config.ini).
         at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:74)
         at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
         at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
         at org.eclipse.core.runtime.adaptor.EclipseStarter.main(EclipseStarter.java:150)
    So maybe this is the real problem. I am sorry but i am not really used to launch java applications from console (i always do it with eclipse) so, i don't really know if i need some more parameters or what happen.
    My config.ini file is the same that eclipse uses when it launches the application, and the dev.properties file is also the same.

Maybe you are looking for