Code Comments
Programming Forum and web based access to our favorite programming groups.I saved a bean as follows in the
C:\Tomcat5\webapps\hasanbabu\WEB-INF\classes\hasanbabu\testBean.class
package hasanbabu;
import java.io.*;
public class testBean{
FileWriter fw;
public testBean(){
try{
fw = new FileWriter("log.txt",true);
}
...
}
public String log( String s){
try{
fw.write(s+"\r\n");
return "Done.";
}
catch(Exception e){
return ("Exception"+e);
}
}
....
}
And the jsp page in the C:\Tomcat5\webapps\hasanbabu\test.jsp
<jsp:useBean id="test" class="hasanbabu.testBean" />
...
<% String name = request.getParameter("name"); %>
...
<%=log(name) %>
The jsp page works well and since it does not throw any exception
(the output in the browser shows "Done."), it is clear that te file
log.txt is created and written. However i can't locate where file
log.txt. Can any one help me...
Post Follow-up to this messageHi, did u try to do F3 to search the file from c:\ ? > The jsp page works well and since it does not throw any exception > (the output in the browser shows "Done."), it is clear that te file > log.txt is created and written. However i can't locate where file > log.txt. Can any one help me...
Post Follow-up to this messageHi,
I tryed to copy your example and make it more simple:
C:\Programmi\Apache Group\Tomcat
4.1\webapps\hasanbabu\WEB-INF\classes\hasanbabu\testBean.java
package hasanbabu;
import java.io.*;
public class testBean{
public testBean(){
//try{
// fw = new FileWriter("log.txt",true);
//}
//....
}
public String log(String aString){
return "test";
}
}
C:\Programmi\Apache Group\Tomcat 4.1\webapps\hasanbabu\test.jsp
<jsp:useBean id="test" class="hasanbabu.testBean" />
<% String name = request.getParameter("name"); %>
<html>
<body>
<%=log(name) %>
</body>
</html>
but I get:
<begin>
description The server encountered an internal error () that prevented
it from fulfilling this request.
exception
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 4 in the jsp file: /test.jsp
Generated servlet error:
[javac] Compiling 1 source file
C:\Programmi\Apache Group\Tomcat
4. 1\work\Standalone\localhost\hasanbabu\te
st_jsp.java:60: 'void' type
not allowed here
out.print(log(name) );
^
1 error
at
org.apache.jasper.compiler.DefaultErrorHandler.javacError(DefaultErrorHandle
r.java:130)
at
org.apache.jasper.compiler.ErrorDispatcher.javacError(ErrorDispatcher.java:2
93)
at org.apache.jasper.compiler.Compiler.generateClass(Compiler.java:353)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:370)
at
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:4
73)
at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:1
90)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Application
FilterChain.java:247)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterCh
ain.java:193)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.ja
va:256)
at
org.apache.catalina.core. StandardPipeline$StandardPipelineValveCo
ntext.invok
eNext(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.ja
va:191)
at
org.apache.catalina.core. StandardPipeline$StandardPipelineValveCo
ntext.invok
eNext(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:2417)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180
)
at
org.apache.catalina.core. StandardPipeline$StandardPipelineValveCo
ntext.invok
eNext(StandardPipeline.java:643)
at
org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.
java:171)
at
org.apache.catalina.core. StandardPipeline$StandardPipelineValveCo
ntext.invok
eNext(StandardPipeline.java:641)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172
)
at
org.apache.catalina.core. StandardPipeline$StandardPipelineValveCo
ntext.invok
eNext(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$StandardPipelineValveCo
ntext.invok
eNext(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:193)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:781)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConne
ction(Http11Protocol.java:549)
at
org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:589)
at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.jav
a:666)
at java.lang.Thread.run(Thread.java:536)
----------------------------------------------------------------------------
----
Apache
<end>
I am also trying to make some test with tomcat.
How could u make your webapp working ?
I only made the 2 files u said. Did u edit any .xml file ?
regards,
Fabio
Post Follow-up to this messageFabio Ferronato <invalid@invalid.invalid> wrote in message news:<n8Q_b.29379$Kc3.902760@twi
ster2.libero.it>...
> Hi,
>
> I tryed to copy your example and make it more simple:
>
> C:\Programmi\Apache Group\Tomcat
> 4.1\webapps\hasanbabu\WEB-INF\classes\hasanbabu\testBean.java
>
> package hasanbabu;
>
> import java.io.*;
>
> public class testBean{
> public testBean(){
> //try{
> // fw = new FileWriter("log.txt",true);
> //}
> //....
> }
>
> public String log(String aString){
> return "test";
> }
>
> }
>
> C:\Programmi\Apache Group\Tomcat 4.1\webapps\hasanbabu\test.jsp
>
> <jsp:useBean id="test" class="hasanbabu.testBean" />
> <% String name = request.getParameter("name"); %>
> <html>
> <body>
> <%=log(name) %>
I'm sorry i made a mistake here while typing the application to
the groups. this line should be
<%=test.log(name) %>
> </body>
> </html>
Thanks a lot for your effort.
Although my purpose of the test.log() method is just to update a
file in the server, i'm returning a String argument just to check
wether the bean throws any exception, and the output in my browser
clearly shows there's none.
I searched for this file in My Computer, and sure it's not there. I
even tried to make the file log.txt in each possible directory, and
checked wether the bean updates the file.. the bean doesn't and yet
did not throw any exception. My question is why did the bean had not
thrown any exception.
I tried to use FileWriter in simple command line application. the
FileWriter appends the file when each time the write() method is
called. and if the file is not there it just creates one. If the file
is there and if it do not have write permission, the method throws
IOException.
Hasan Babu H
hasanbabu@yahoo.com
> I am also trying to make some test with tomcat.
> How could u make your webapp working ?
> I only made the 2 files u said. Did u edit any .xml file ?
>
> regards,
> Fabio
Post Follow-up to this message> > C:\Programmi\Apache Group\Tomcat
I placed the same testBean.class in the again and placed it in
C:\Apache Software\Tomcat5\webapps\hasanbabu\WEB-INF\classes\hasanbabu\testB
ean.class
I started Tomcat from windows start menu. when tested everything
works well and now i could trace the log.txt file in an unexpected
directory, C:\Winnt\Profiles\Hasanbabu\Start Menu\Programs\Apache
Software\log.txt
I shutdown tomcat, and restarted it from the command prompt by
typing
C:\> cd Program Files\Apache Software\Tomcat5\bin
C:\> tomcatw
now when i run the same application log.txt is written to the
tomcat5/bin directory.
I made the bean to write the file to my webapps directory by
changing the line as follows:
package hasanbabu;
import java.io.*;
public class testBean{
public testBean(){
try{
fw = new FileWriter("..\webapps\hasanbabu\log.txt",true);
}
//....
}
public String log(String aString){
return "test";
}
}
But this works only if i start the tomcat in command prompt
from tomcat's bin directory.
Hasan Babu H
Post Follow-up to this message>
> public class testBean{
> public testBean(){
> try{
> fw = new FileWriter("..\webapps\hasanbabu\log.txt",true);
> }
> //....
> }
>
hum,
maybe to make indipendent from any path from which u start the tomcat,
u should write something like
fw = new FileWriter("%catalina_home%\webapps\hasanbabu\log.txt",true);
I dont know if it could work.
I am also pretty new to tomcat.
I think there must be someway to find the document base at runtime and
use it.
cheers,
Fabio
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.