Compiling my first servlet
I tried to compile HelloWorldServlet.java(taken from sunexamples) stored in JavaWebServer2.0\servlets.
I have JavaWebServer2.0 and have included servlet.jar in my environment variables.
I was getting an error can't find class sun/tools/javac/main.
Then,I took tools.jar from my jdk1.3, and pasted in JavaWebServer2.0\lib and included tools.jar in environment variables.
Now I get errors:
java.lang.NoClassDefFoundError:java/util/ArrayList
at sun.tools.util.CommandLine.parse(Compiled Code)
at sun.tools.javac.Main.compile(Compiled Code)
at sun.tools.javac.Main.main(Main.java:729)
PLEASE HELP ME.
Is it wrong to copy-paste tools.jar?How can I compile?
Here is part of a batch file I use for my command line compiling.
SET JAVA_HOME=C:\jdk1.3.1_09
SET CLASSPATH=.;C:\jdk1.3.1_09\lib\jt400.jar;C:\jdk1.3.1_09\lib\tools.jar;C:\jdk1.3.1_09\lib\classes12.zip;C:\jdk1.3.1_09\lib\jregex1.2_01.jar
SET PATH=c:\jdk1.3.1_09\binCreate a file with extension .bat and add this. Make changes to your jars and directories as needed.
Similar Messages
-
Can't compile my first servlet program
hi guys,
there are some problems with compiling the first servlet program(helloservlet).
the error is following
C:\SERVLET-CODE\hello1>javac HelloServlet.java
HelloServlet.java:4: package javax.servlet does not exist
import javax.servlet.*;
^
HelloServlet.java:5: package javax.servlet.http does not exist
import javax.servlet.http.*;
^
HelloServlet.java:15: cannot resolve symbol
symbol : class HttpServlet
location: class HelloServlet
public class HelloServlet extends HttpServlet {
^
HelloServlet.java:16: cannot resolve symbol
symbol : class HttpServletRequest
location: class HelloServlet
public void doGet(HttpServletRequest request,
^
HelloServlet.java:17: cannot resolve symbol
symbol : class HttpServletResponse
location: class HelloServlet
HttpServletResponse response)
^
HelloServlet.java:18: cannot resolve symbol
symbol : class ServletException
location: class HelloServlet
throws ServletException, IOException {
^
6 errors
i don't know why it can not find the import java.*
and i already set up the classpath
and my code is
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
/** Simple servlet used to test server.
* <P>
* Taken from More Servlets and JavaServer Pages
* from Prentice Hall and Sun Microsystems Press,
* http://www.moreservlets.com/.
* © 2002 Marty Hall; may be freely used or adapted.
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String docType =
"<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 " +
"Transitional//EN\">\n";
out.println(docType +
"<HTML>\n" +
"<HEAD><TITLE>Hello</TITLE></HEAD>\n" +
"<BODY BGCOLOR=\"#FDF5E6\">\n" +
"<H1>Hello</H1>\n" +
"</BODY></HTML>");
please help me out of it...
thank you all...hi man,
thanks for the classpath, and i already did it in system environment.
but it can not work either...
do i really have to download the API, so where i have to put it after i download it... -
Compiling my first servlet page
Hi,
Im not able to compile my servlet.The servlet code is in desktop\java.The servlet.jar is in c:\program files \ apache tomcat 4.0\common\lib
when i give this command
javac HelloServlet.java -classpath " c:\--------" it is not working.I dont know whether this is correct.Please help me out.Adding the servlet.jar to tomcat won't make the java compiler know where it is unless the code is called from an application in the web container.
use javac -cp "filename"
Otherwise I'd suggest you'd get an IDE to which you add the jar and then compile using the IDE.
Don't waste your time with javac! -
Compile java applications,servlets etc.
I am a newbie to java...what do i need to compile java applications,servlets etc.
first you need java developers kit(jdk)
download it
then r.click on my computer and take it's properties
go to advance properties
go to envirinment variable
set variables
JAVA_HOME set to directory where you installed jdk
CLASS_PATH set to the bin in your jdk
then write a java class and save somewhere as .java file
go to command prompt
change directory to where you save java class
and use javac (yourjavafilename) .java command to compile it
wish you all the best -
Having problem in compiling and deploying servlet
please tell me about environment variable because i m totally confused.i want to know why do i need to set environment variable.and how would it help me to compile and deploy my first servlet.
i also want to know about Class path and path.
please tell me this.
i'll really appreciatethanks a lot.
i got my first servlet compiled deployed and run.
thanks againYou are welcome. If you think it really help, you can assign duke star to me :)
Good luck to your web application. -
My First servlet error-HTTP Status 500
Recently Installed apache-tomcat-5.5.27 ,I followed one documentation when i googled for a while like is here [http://linux-sxs.org/internet_serving/c292.html]
when i try to access from web-browser ,it came up with errors like
HTTP Status 500 -
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
javax.servlet.ServletException: Error allocating a servlet instance
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)
root cause
java.lang.UnsupportedClassVersionError: Bad version number in .class file
java.lang.ClassLoader.defineClass1(Native Method)
java.lang.ClassLoader.defineClass(ClassLoader.java:620)
java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:1876)
org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:889)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1353)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1232)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:875)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
java.lang.Thread.run(Thread.java:595)
note The full stack trace of the root cause is available in the Apache Tomcat/5.5.27 logs.Here is the directory structure
#/opt/apache-tomcat-5.5.27/webapps/MyFirst
#/opt/apache-tomcat-5.5.27/webapps/MyFirst/WEB-INF
#/opt/apache-tomcat-5.5.27/webapps/MyFirst/WEB-INF/classes
#/opt/apache-tomcat-5.5.27/webapps/MyFirst/WEB-INF/libI placed web.xml file in WEB-INF directory and HelloWorld.class in WEB-INF/classes and MyFirst.xml in /opt/apache-tomcat-5.5.27/conf/Catalina/localhost/
the files typically contains
web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</servlet-mapping>
</web-app>
HelloWorld.java
// Filename : HelloWorld.java
// Description : This servlet merely says hello!
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld extends HttpServlet {
public void doGet ( HttpServletRequest request, HttpServletResponse response )
throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>Hello, Cruel World!</title></head>");
out.println("<body>");
out.println("<h1>Hello, Cruel World !</h1>");
out.println("This is my first servlet.");
out.println("</body>");
}// end doGet
}///:~
MyFirst.xml
<!-- MyFirst Context -->
<Context path="/MyFirst" docBase="MyFirst" debug="0" reloadable="true"/>anybody have idea about this error...miriyalasrinivas wrote:
java.lang.UnsupportedClassVersionError: Bad version number in .class fileThe class is compiled with a JDK version which is newer than the JRE version used to run the class. To solve this, just clean up your Java environment and align the versions. You can get version information of the Java compiler using javac -version and of the Java runtime using java -version.
That said, this problem is actually not related to servlets. You didn't get a root exception of javax.servlet package. You just got a root exception of java.lang package, which basically makes it a Java SE problem. Questions related to those actually belongs in the 'New to Java' forum. -
Trying to run my first servlet through Eclipse + XAMPP
I'm trying to run my first servlet through eclipse, I'm using XAMPP + Tomcat add-on as my webserver. How do I even try and compile my servlet? I've added the external jar Servlet-api.jar to my project as stated in here, http://www.theserverside.com/discussions/thread.tss?thread_id=37924
But eclipse wouldn't compile it, because there just isn't a main() in my servlet program..
Do I need to install the WPT plugin for eclipse? I'm guessing I'm not setting my CLASSPATH correctly - Do I need to set it up manually?Nevermind, there were lots of Issues going the XAMPP way, so I just installed Tomcat separately and all is fine now.
I used instructions from http://www.scribd.com/doc/495993/Installing-Apache-Tomcat-6-and-Using-It-With-Eclipse and it was a walk-in-the-park.. -
How to compile and run servlets in Eclipse?
Does somebody known how can I compile and run servlets in Eclipse IDE? I've added and configured Tomcat's plugin. I've created a project with my example servlets source, and I don't know what farther. How do I have compile it without main method? I must add web.xml file from Tomcat's directory into projects in Eclipse and modify it?
THX ChudzikTry googling for "eclipse servlet", surely someone has written instructions.
-
Help required in First Servlet
Hey Guys.....I have read the above thread all posts and as this is also my first Servlet so I am also getting
java.lang.ClassNotFoundException: servlets.HelloWorldServlet
Now in my Apache tomcat folder C:\apache-tomcat-6.0.16\webapps\ServletExamples I have the WEB-INF folder.....which has the web.xml....
Web.xml is something like this...
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
version="2.5">
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>servlets.HelloWorldServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>servlets.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/HelloWorldServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
</web-app>The HelloWorldServlet.java is
package servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class HelloWorldServlet extends HttpServlet{
public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
PrintWriter pw = response.getWriter();
pw.println("<html>");
pw.println("<head>");
pw.println("</head>");
pw.println("<body>");
pw.println("<h3>Hello World as a Servlet</h3>");
pw.println("</body>");
pw.println("</html>");
}and this is what I am writing on the url......
http://localhost:8080/ServletExamples/HelloWorldServlet
and I am assuming that the problem is coming in the <servlet-class> in the fully qualified name....
So I decided to make a classes folder in the WEB-INF folder and copy all my .class files and .java files in it.....
after this I am still getting the same error....
java.lang.ClassNotFoundException: servlets.HelloWorldServlet
and when I refresh it again it gives me a different error....which is
type Status report
message Servlet HelloWorldServlet is not available
description The requested resource (Servlet HelloWorldServlet is not available) is not available.
So how can anybody help me out in starting my carrier in the servlets...
Thanks in advance
Regards
ISIPlease can anyone suggest any good tutorials which can help me in this.....I am following this one but I am unable to overcome this error...
http://java.sun.com/j2ee/tutorial/1_3-fcs/doc/Servlets.html
Regards
ISI -
Hi
I am trying to run my first servlet HelloWorld
I have my servlet in the directory
Tomcat 4.1/webapps/test/web-inf/classes/HelloWorld.class
and my web.xml file in the directory
Tomcat 4.1/webapps/test/web-inf/web.xml
contains the following lines
<web-app>
<servlet>
<servlet-name>HelloWorld</servlet-name>
<servlet-class>HelloWorld</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>HelloWorld</servlet-name>
<url-pattern>/HelloWorld</url-pattern>
</web-app>
I also have changed the conf/server.xml file for the context as follows
<Context path="/test" docBase="test" debug="0"
reloadable="true" crossContext="true">
and now when I try http://localhost:8080/test/servlet/HelloWorld
Still I am getting the error status 404 The requested resource /test/servlet/HelloWorld not found.
What am I doing wrong ????
When I put my HelloWorld.class file in the webapps/examples directory it runs fine.WHy is it so ?
Also for the above I have not started my tomcat server since I tried to run my HelloWorld from examples using http://localhost:8080/examples/servlet/HelloWorld it works perfect so I think I do not need to start server.
Please reply meTry fully qualifying your servlet-class so that it reads something like this: <servlet-class>examples.servlet.HelloWorld</servlet-class>
-
Problem compiling my first program; Please Help me!
Please HELP, what am I doing wrong?
For over 5hours I have been trying to figure out how to compile a simple Hello world program using sdk1.3.1_02/j2re1.3.1_02 and I am getting the following errors: helloworld.java:2 cannot resolve symbol
symbol : class string
location : class helloworld
cannot reolve the string symbol
symbol : class out
location : package system
I want to program in java so badly but I am trying to get my environment set so that I can take off. To compile my first program has been a disaster!!
This is my path:
SET PATH=C:\WINDOWS;C:\WINDOWS\COMMAND;C:\JDK1.3.1_02\BIN
Thanks very much in advance
::(Java is case sensitive,
use String instead of string. and System.out instead of system.out
Sudha -
Hi
I have recently downloaded jakarta-tomcat3.3a and i'm trying to compile my simple servlets,but i have an error saying the
"import javax.servlet.*" not found and many more.
It seems to me that i'm missing servlet.jar file.
Now how do i set this.I'm sure it should be in classpath but i need to know where will i create my CLASSPATH variable,i mean to say is it in user variable or system variable.
I have already set my PATH in <control panel><system>environmental variable>USer variable>.
But i have not set any classpath till now as it was not necessary for me to run my java programs.
But now i think i have set the CLASSPATH.
I have my tomcat in C:\jakarta-tomcat-3.3a
Can anyone give me the exact path to set.
Thanks in advance.The difference between System and User environment variables are simply who has access to them. When you set a System EV, it will persist regardless of the logged in user. User variables are specific only to that user. Which one you decide to set depends on which you really want.. but i believe User variables will override System variables.
Your classpath should then include..
c:\tomcat_install_dir\lib\servlet.jar -
How to install servlet classes in order to compile a simple servlet...
When trying to compile a simple servlet (java file), I get errors having to do with not finding any object of the javax.servlet class. I am using J2SE v.1.4, and from what I know, it does not have built-in support for Servlets-JSP.
Do I need to install myself the servlet classes (downloaded from Sun's site) in order for my servlet to be able to compile and work under tomcat? And if so, where should I put them? Or is there something else I have to do?
Thank you in advance for your assistance!If you have Tomcat already, the files you require are in:
(Tomcat4)
[TOMCAT_HOME]/common/lib/servlet.jar
or
(Tomcat5)
[TOMCAT_HOME]/common/lib/servlet-api.jar
[TOMCAT_HOME]/common/lib/jsp-api.jar
This file needs to be added to your classpath when compiling a servlet. -
Running my first Servlet on TOMCAT - 10 duke dollars
I am very new to Servlets. I am not creating a seperate context on Tomcat root to load the Servlet.
I did the automatic installation of Tomcat 4.0.3 on windows NT available on <jakarta.apache.org/tomcat>
I am going to load my servlet class in c:\<Tomcat Home>\Web Apps\Root\Web-inf\Classes
But under my <Root\Web-inf> there is NO <Classes> subdirectory. So I created one and copied my class file there.
Then on the browser, I typed
http://127.0.0.1:8080/servlet/myFirstServlet
Then I am getting the 404 Http Not found error.
Error in detail is "/servlet/myFirstServlet" not found
Can someone PLEASE help me ASAP.NOTE: I already sent this message under different heading.. I am sending this message under this for Mr/Mrs w234 ....
Please let me know....
I wrote my first Servlet with Forms, for a registration system. I have my input HTML file first.html and my java class (first.java) which processes the form and spits out the same information thru' the servlet.
I added the line below in my server.xml in /conf directory, Forms is the subdirectory under webapps
<Context path="/Forms" docBase="Forms" debug="0"
reloadable="true" crossContext="true" />
I created the web.xml as follows in c:<Tomcat home>\webapps\Forms\web-inf\web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>
<servlet>
<servlet-name>first</servlet-name>
<servlet-class>first</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>first</servlet-name>
<url-pattern>/first</url-pattern>
</servlet-mapping>
</web-app>
Note : My HTML file name and class files name both are same.. Also can someone tell me how to change web.xml for different HTML file name and class name ? Or do we have to include HTML file here in web.xml ?
I am confused !!
Then in the browser I typed
http://127.0.0.1:8080/Forms/servlet/first.html
I am getting this error
Apache Tomcat/4.0.3 - HTTP Status 404 - /first.html
type Status report
message /first.html
description The requested resource (/first.html) is not available.
Can you please HELP ...
Still I have not figure out how to give a couple of Duke s ? Please help me ... -
Fail to run my first Servlet with Sun ONE Studio 4 Update 1 (+ bi Tomcat)
Hello !
I failed to run my first Servlet with Sun ONE Studio 4 update 1 ( with built in Tomcat)
I think that I followed most of the online instructions,
so I successfully run a JSP file,
but I failed with my first servlet:
The error message is:
"Standard Wrapper[:MyServlet]: Marking servlet MyServlet as unavailable
javax.servlet.ServletException: Wrapper cannot find servlet class com.hemmerling.myservlet.MyServlet
or a class it depends on
So please don�t ask me for the code of the servlett ( simply taken from a book),
but tell me why the one-and-only servlett was not found. what might I have done wrong, if I did everything I did to run the JSP file, too ?
Of couse I copied the file into the "Classes" directory of the Webmodule ( WEB-INF ) and "processed" it, so that I was able to execute it.
Any suggestions ?
Tia
Sincerely
RolfTough to say, but try:
1. Put the servlet in a package. If you're using the default package (class file in WEB-INF/classes directory, then Tomcat may not find it.
2. Check out web.xml to ensure the <servlet> and <servlet-mapping> entries are correct.
3. Make the servlet as simple as possible so you're sure that it is the servlet itself that cannot be found and not some other class that it uses.
Good Luck
Maybe you are looking for
-
How to install pixma MX420 windows 8
have a new computer using windows 8 want to install a cannon pixma mx420 all in one printer cannot seem to get it installed
-
ACs For Windows 4.1.(1) build 23
Hi. We´ve got two Windows 2003 Server R2 machines, with installed Cisco ACS For Windows 4.1.(1) Build 23 used for RADIUS users authentication and now days we´re trying to deploy now a TACACS+ configuration to the network device manage now from those
-
How to make a TOC link to comments?
Hi, I've annotated several PDF documents with GoodReaer, and have used their annotation tools to insert comments within certain blocks of text. I've been using the same categories for these comments, so that they essentially function as tags. I'm p
-
Putting an image in a scroll pane
This is probably a simple question for most of you, but I need a little bit of help. How do I put a picture in a scroll pane? The problem I have is that I can load an image and display it, that works fine. However, let's say I am making a new frame (
-
EEM Script to reload router only once after tracked object is down.
event manager applet vpn_tunnel_unreachable event track 456 state down action 1.0 reload I need it to reload only once if tracked object 456 is down. It should reload the router and then if the tracked object is still down it should go into dial back