Problems compiling a servlet
Hello,
I recently installed Tomcat 4.1.24 and I am trying to compile a servlet but with no success. The error I get is package javax.servlet does not exist. I have set up jdk1.3.1-3 and the environment paths. I have been successful in compiling regular java applications. I am currently just using the dos prompt and command line c:\javac somefile.java
When I tried to compile a servlet, I ran into the javax.servlet error so I found a javax.jar file and added it to the jdk1/3/1-3\lib directory but the compile still fails.. I even tried to add it to the environment path but that still doesn't work...
could someone tell me where I would need to add the javax.jar file? and what adjustment I need to make to be able to compile servlets?
thanks in advance for any help
gjcat777
You need to get J2EE (Java 2 Enterprise Edition). Download it and install it. It's basically a couple of JAR files that you need to use. Under $J2EE_HOME/lib there is a file called J2EE.jar Include that JAR file into your project and carry on with your servlet development.
Similar Messages
-
Problem compiling HelloWorld servlet
Hello,
I'm trying to compile a "Hello World" servlet in Tomcat that I copied straight out of the book. The code is as follows:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloWorld1 extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<head>");
out.println("<title>Hello World!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
However, neither HttpServlet, HttpServletRequest, HttpServletResponse, or ServletException are being recognized. In each case, the message I'm getting from the compiler is "cannot resolve symbol." I'm finding this whole situation very distressing. If someone could help me out, I'd greatly appreciate it.
Thanks,
Adamwell i have tried out both Servlets and JSPs in Windows 98 and i did not get the problem you have mentioned, i am using Jakarta Tomcat 3.2.1, and i have set the classpath to servlet.jar, actually this file is present within the jakarta-tomcat-3.2.1\lib directory and i suppose the classpath is automatically set as u run the startup.bat file. What you can try is, while setting the TOMCAT_HOME and ANT_HOME in the autoexec.bat, try doing it using the old dos 8.3 file naming style, for eg.
set JAVA_HOME=C:\jdk1.3
set TOMCAT_HOME=c:\jakart~1.1
set ANT_HOME=c:\jakart~1.1
then try running the example again. -
Problem compiling simple servlet
I am trying to compile a very simple servlet.
When I do, I get the following error message:
Package javax.servlet does not exist
I am using the Java 2 SDK, Standard Edition Version 1.3.1.
I have downloaded the servlet api (zip file servletapi2_1_1win.zip)
from Sun's site. I unzipped these files in my lib directory; there are two folders,
one called api and the other called src. Api and Src directories have their own
sub-folders, javax/servlet/http etc.
I am using W2K ; I had to create a CLASSPATH system variable in the environment
variables section of control panel since there was none defined.
I added the following line:
C:\jdk1.3.1_01\lib\api\javax\servlet;C:\jdk1.3.1_01\lib\api\javax\servlet\http;
I also did this for the PATH statement..
My servlet looks like this:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class howdy extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("<HTML>");
out.println("<HEAD><TITLE>Hello World </TITLE></HEAD>");
out.println("<BODY>");
out.println("<BIG>Hello World </BIG>");
out.println("</BODY></HTML>");Thanks. I was able to figure it out by specifying the
full classpath
at the command line, like this:
C:> javac -classpath
C:\jdk1.3.1_01\lib\servletapi2_1_1-win.zip\MyServlet.ja
a
Apparantly the system doesn't acknowledge the
environmental variable that
I created in the control panel; also I have no
autoexec.bat file...so it
looks like I have to write out the full path whenever
I need to compile
something. Kind of bothersome, but at least it
works.
You shouldn't have to do this. What operating system are you using?
If you are using win2000, winNT or winxp, you should set the classpath in your system environment varialbes. You can also make a config.bat file and put everything in there. Then just run this config.bat file to set up your environment once for every session.
Here's a file that I have set up on one of our NT machines. I just double click the icon for this file on my shortcut, and it gives me the window where I can compile my java programs.
Hope this helps.
Kamran
=========== File SetJava.bat ============
set PATH=%PATH%;m:\jdk1.3\bin
set CLASSPATH=m:\jdk1.3\jre\lib;m:\jdk1.3\jaxp-1.1\jaxp.jar;m:\jdk1.3\jaxp-1.1\crimson.jar;m:\jdk1.3\jaxp-1.1\xalan.jar;.
cd cis235
%SystemRoot%\system32\cmd.exe -
Problems Compiling javax.servlet and javax.servlet.http
When I try to compile a program that imports both javax.servlet and javax.servlet.http, the compiler keeps telling me that "package javax.servlet does not exist"... I have place the javax.servlet packages in the src.zip and in the src folder but i dont understand why the compiler isnt picking them up. Maybe I did something wrong ... could someone help please
Try to compile vith the option "-classpath /your/path/to/servlet.jar"
-
I've been trying to do the tutorials in a book titled Apache Jakarta-Tomcat as part of my introduction to JSP. I'm new to Java but do know the basics. I have on my machine Java 1.3, Java 1.4, Java FrameWorks 2.1 and Jython 2.1 on Win2000 Pro. So enough about my configuration. I have never worked with packages also.
I downloaded the files from the books site due to the fact I make a lot of typos when hand coding Java (I've become a pretty good debugger of my own code). But everytime I go to compile the *.java I get error messages. So below you will find HelloTag.java and beneath that the error messages that are thrown when I try and compile it. I tested other bits of *.java and have had no problem compiling them. Is there a JSP module I'm missing?
Am I doing something wrong or am I missing something from my configuration.
Marijan Madunic
package chapter2;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspTagException;
import javax.servlet.jsp.tagext.TagSupport;
public class HelloTag extends TagSupport
public void HelloTag() {
// Method called when the closing hello tag is encountered
public int doEndTag() throws JspException {
try {
// We use the pageContext to get a Writer
// We then print the text string Hello
pageContext.getOut().print("Hello");
catch (Exception e) {
throw new JspTagException(e.getMessage());
// We want to return SKIP_BODY because this Tag does not support
// a Tag Body
return SKIP_BODY;
public void release() {
// Call the parent's release to release any resources
// used by the parent tag.
// This is just good practice for when you start creating
// hierarchies of tags.
super.release();
D:\Java\JDK 1.3\bin>javac HelloTag.java
HelloTag.java:3: cannot resolve symbol
symbol : class JspException
location: package jsp
import javax.servlet.jsp.JspException;
^
HelloTag.java:4: cannot resolve symbol
symbol : class JspTagException
location: package jsp
import javax.servlet.jsp.JspTagException;
^
HelloTag.java:5: cannot resolve symbol
symbol : class TagSupport
location: package tagext
import javax.servlet.jsp.tagext.TagSupport;
^
HelloTag.java:7: cannot resolve symbol
symbol : class TagSupport
location: class chapter2.HelloTag
public class HelloTag extends TagSupport
^
HelloTag.java:14: cannot resolve symbol
symbol : class JspException
location: class chapter2.HelloTag
public int doEndTag() throws JspException {
^
HelloTag.java:20: cannot resolve symbol
symbol : variable pageContext
location: class chapter2.HelloTag
pageContext.getOut().print("Hello");
^
HelloTag.java:24: cannot resolve symbol
symbol : class JspTagException
location: class chapter2.HelloTag
throw new JspTagException(e.getMessage());
^
HelloTag.java:28: cannot resolve symbol
symbol : variable SKIP_BODY
location: class chapter2.HelloTag
return SKIP_BODY;
^
HelloTag.java:37: cannot resolve symbol
symbol : variable super
location: class chapter2.HelloTag
super.release();
^
9 errorsWell, it looks like you've not got the servlet development kit JAR on your classpath. I think it'll probably be called servlet.jar on your system. Add that to the classpath if it's not already there.
Incidentally, you've bumped into one of the areas Java's slightly lenient - declaring a method that looks like a constructor:
public HelloTag() { }
public void HelloTag() { }The first is a constructor, the second is a normal method. I'm assuming you intended to have the former instead of the latter.
Anyway, hope this helps. -
Create problem when compiling the servlet
hi,
i got a problem when i compile a servlet
when i try to compile the servlet, it shows that it could
not found the classes like httpservlet, etc.
means the classes of the servlet
i am using the j2sdk1.4.1 edition,
i had include the javax.servlet.*; in the program
please tell me what can be the problem & especially any solution for thatthe javax.servlet package and it's sub packages (javax.servlet.http, javax.servlet.jsp, javax.servlet.jsp.tagext) are not included with the Standard Edition. These packages are part of the Enterprise Edition. Check out this link for download:
http://java.sun.com/j2ee/sdk_1.3/ -
Hi, i have a problem to compile a servlet, i will try to explain my problem easily...
i have a JavaBena class int he directory.....C:\Programmi\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes......and i have compiled it by DOS commands, everyhting has gone well!
i have a Servlet class in the same directory where it situated the JavaBean. i compile the Servlet as well as i have done with the Javabean, by DOS commans, including the Tomcat servlet api.
this is the command which i use to compile the servlet.......javac ServletRegistraUtente.java -classpath "C:\Programmi\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar".....
but everything i get this error...
C:\Programmi\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes>javac ServletRicercaUtente
.java -classpath "C:\Programmi\Apache Software Foundation\Tomcat 6.0\lib\servlet-api.jar"
ServletRicercaUtente.java:20: cannot find symbol
symbol : class BeanRicercaUtente
location: class ServletRicercaUtente
^
ServletRicercaUtente.java:20: cannot find symbol
symbol : class BeanRicercaUtente
location: class ServletRicercaUtente
BeanRicercaUtente m_BeanRicercaUtente = new BeanRicercaUtente();
^
2 errors
C:\Programmi\Apache Software Foundation\Tomcat 6.0\webapps\ROOT\WEB-INF\classes>
these are the 2 classes....
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*;
import JavaBean.BeanRicercaUtente;
public class ServletRicercaUtente extends HttpServlet
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException
ServletContext sc;
RequestDispatcher rd;
try
BeanRicercaUtente m_BeanRicercaUtente = new BeanRicercaUtente();
request.setAttribute("m_BeanRicercaUtente", m_BeanRicercaUtente);
String codiceFiscale = request.getParameter("codice");
m_BeanRicercaUtente.effettuaRicerca(codiceFiscale);
sc = getServletContext();
rd = sc.getRequestDispatcher("/risposta.jsp");
rd.forward(request, response);
catch(Throwable theException){}
import java.sql.*;
public class BeanRicercaUtente
String nome, cognome, indirizzo, telefono;
public void effettuaRicerca(String codiceFiscale)
try
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://.................";
Connection con = DriverManager.getConnection(url);
Statement cmd = con.createStatement();
String qry = "SELECT ..................";
ResultSet res = cmd.executeQuery(qry);
while (res.next())
cognome = res.getString(1);
nome = res.getString(2);
indirizzo = res.getString(3);
telefono = res.getString(4);
res.close();
cmd.close();
con.close();
catch (SQLException e)
e.printStackTrace();
catch (ClassNotFoundException e)
e.printStackTrace();
i would be glad to get help about it...! :) thanks!i am sorry, but in the first class i have not written "import JavaBean.BeanRicercaUtente;"
i have only these imports...
import javax.servlet.http.*;
import javax.servlet.*;
import java.io.*; -
I have a problem compiling servlets bymeans of NetBeans IDE 3.6.
If I compile a servlet by means of another IDE, they are oK and work well with NetBeans too.
On the contrary, if I compile it bymeans of Netbeans 3.6, I get a .class which does not work. I
have realized also that for instance if the .class i get with the other IDE is 1,58 KB, if I use
NetBeans I get a .class smaller, that is 1,53 Kb.
Can you help me?
Thanks
Eugenia Marianiok
This is the servlet named Contatore.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Contatore extends HttpServlet
private int conta;
public void init(ServletConfig config) throws ServletException
conta = 0;
public void doGet(HttpServletRequest richiesta, HttpServletResponse risposta)
throws IOException, ServletException
conta++;
risposta.setContentType("text/html");
PrintWriter out = risposta.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Pagina con contatore</title>");
out.println("</head>");
out.println("<body>");
out.println("Questa pagina e' stata visualizzata");
out.println("<h1>"+conta+ "</h1> volte.");
out.println("</body>");
out.println("</html>");
out.close();
Before using the compiler of NetBeans (that is after getting Contatore.class by means of Bluej) when I use Execute I see in Internet Explorer 6.0 with win Xp Pro at the
http://localhost:8084/esempi/Contatore
Questa pagina e' stata visualizzata
1
volte.
and Contatore.class is 1,58 KB
After that I use the compiler of NetBeans when I use Execute here the error from Tomcat 5.0
I see in Internet Explorer 6.0 with win Xp Pro at the
http://localhost:8084/esempi/Contatore
HTTP Status 404 - Servlet Contatore is not available
type Status report
message Servlet Contatore is not available
description The requested resource (Servlet Contatore is not available) is not available.
Apache Tomcat/5.0.19
and Contatore.class is 1,53 KB
I hope to have said everything
I wait a help, please.
Thanks -
Compiling a Servlet that uses JavaBean
I have a servlet that will get data from a JavaBean which is created before in a jsp file. While I trying to compile the servlet I am getting this message:
--------------------Configuration: JDK version 1.3 <Default>--------------------
Command : "C:\jdk1.3\bin\javac.exe" -d "C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes" C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes\MyServlet.java
Directory : C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes
C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes\TasitKayitGirisi.java:19: cannot resolve symbol
symbol : class SimpleBean
location: class MyPackage.SimpleBean
SimpleBean simpleBean = (SimpleBean) session.getAttribute
^
("simpleBean");
C:\jakarta-tomcat-3.2.1\webapps\ROOT\WEB-INF\classes\MyServlet.java:19: cannot resolve symbol
symbol : class SimpleBean
location: class MyPackage.SimpleBean
SimpleBean simpleBean= (SimpleBean) session.getAttribute("simpleBean");
^
2 errors
Process completed.
Where is the problem. SimpleBean is successfully being initializing in my jsp file. But I couldn't compile my servlet that will get data from that bean. Both my servlet and bean are in the same package. I am using JCreator to compile servlets. I think the problem is the compile string that JCreator uses. Can you help me. Thx in advance.Looks like an import Problem.
The Compiler is not able to "see" the SimpleBean Class.
Take care of the Classpath and your imports.
Happy Coding. :-) -
Compiling Java Servlet with Depricated Methods
I have a problem of compiling Java servlets that contain depricated methods. If you compile against modern version of servlet.jar I see depricated methods error messages and if I use a very old servlet.jar it cannot find newer methods. What is is the best solution in this case?
Thank you,
Boris.The best thing to do would be compile your code with the -depreciated option to find which methods have been depreciated and the refactor your code to remove them.
The next best thing is to ignore the messages (they are warnings not errors) and your code should still work -
How to Compile/Run servlet in Tomcat 4.1
Hi All,
iam trying to compile my servlet program in tomcat4.1.. but its showing an error
in the import statement..
UN SOLVABLE SYMBOL... but the import ststement is correct...
can any one help ... is there i have to set any path for compiling/running the servlet...
Thanks in Advicehi thanks for your reply
i have loaded tomcat4.1 exe -- for windows i am starting the tomcat server by clicking from the start menu..
i dint set any env variable .. tell me how to set...
regards
ijay -
Problem compiling Abstract class
Hi
I have writting an abstract class Sort.java and another class BubbleSort.java. I am having problems compiling BubbleSort.java class.
The following is the error message
BubbleSort.java:8: missing method body, or declare abstract
public int doSorting(int[] array);
^
BubbleSort.java:11: return outside method
return num;
^
The following is the code
public abstract class Sort
public abstract int doSorting(int[] array);
}// End of class
public class BubbleSort extends Sort
private int num = 2;
public int doSorting(int[] array);
num = num + 2;
return num;
} // end of classRemove the semi-colon.
public int doSorting(int[] array); // <------- there -
Problem in Download Servlet (Urgent)
Hai
i am using an servlet to download files.
i am facing an problem with that servlet.While downloading, at times it strucks at 290k or 330k.
Note : Acually i am calling this servlet from a popup window.The popup window closes automatically after one minute irrescpective of the download progress.At times i noticed that the download strucks while the popup closes, whether is causes the problem of strucking.
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class Download extends HttpServlet {
HttpSession session =null;
File F;
BufferedInputStream fif;
ServletOutputStream stream;
public void init(){
F=null;
fif=null;
stream =null;
public void doGet(HttpServletRequest request ,HttpServletResponse response) {
try{
// Setting Buffer size
response.setBufferSize(50000);
// Setting Content Type
response.setContentType("application/x-filler");
int buffersize;
String cfile="";
boolean flag=false;
session = request.getSession(true);
//Receiving variables
String fileName= request.getParameter("filename");
String filePath = request.getParameter("filepath");
String downloadFile = filePath + fileName;
F=new File(downloadFile);
String download_date = "sysdate";
String file=F.getName();
buffersize=(int)F.length();
byte b[]=new byte[buffersize];
//Servet output stream to download file
stream = response.getOutputStream();
response.setHeader("Content-Disposition", "attachment; filename=\"" + file + "\";");
int data;
fif = new BufferedInputStream(new FileInputStream(F));
//writing data to output stream
while((data = fif.read()) != -1) {
stream.write(data);
//closing objects
fif.close();
stream.close();
F.delete();
}catch(java.net.SocketException se){
System.out.println("SocketException " +se);
catch(IOException io){
System.out.println("IOException " + io);
catch(Exception e){
System.out.println("Exception " +e);
}I guess your closing of the window is your problem. Your servlet looks just fine to me.
Try calling this servlet from a browser and see if it still stops.. -
Urgent problem in connecting servlet and oracle
Hi
I have problem in connecting servlet with oracle.Kindly let me know what all the classes i should include in classpath to get connected.Where will i find the oracle driver.Kindly help me to do this.
With regrds
Vaijuhttp://www.oracle.com/technology/tech/java/sqlj_jdbc/htdocs/jdbc_faq.html
http://www.oracle.com/technology/sample_code/tech/java/sqlj_jdbc/index.html
http://download-west.oracle.com/docs/cd/B10501_01/java.920/a96654/toc.htm
http://www.oracle.com/technology/software/tech/java/sqlj_jdbc/index.html
http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/index.html -
Problems compiling Zaptel package [SOLVED-ISH]
Hey guys, I'm on an Arch64 system and I'm having problems compiling Zaptel (a dependancy for Asterisk).
Here's the pastebin of the errors I get from the Zaptel makefile: http://pastebin.com/776475
Here's my analysis so far:
There's a line in the Makefile for the zaptel driver that goes like this:
make -C /lib/modules/2.6.17-ARCH/build/ SUBDIRS=/home/woogie/zaptel/src/zaptel-1.2.8 modules
This line activates the kernel's makefile in order to build modules, but specifies that the source directory for zaptel should be included in the make process.
Then things go down the proverbial drain - linux/err_kernel_only.h gets included in the build process, which is designed to do one thing only - stop the build process. So I'm not entirely too sure what's going on here. Is there something misconfigured on my system, or is the Zaptel build system flawed somehow, such that I need to compensate for it?Further information:
I've manually run the problematic make command from /lib/modules/2.6.17-ARCH/build on my own. After reading the kernel makefile documentation, I've learned of the V=1 flag to show me exactly what's going on. The failing command is this one:
gcc -Wp,-MD,/home/cestus/zaptel/src/zaptel-1.2.8/.zaptel.o.d -nostdinc -isystem /usr/lib/gcc/x86_64-unknown-linux-gnu/4.1.1/include -D__
KERNEL__ -Iinclude -include include/linux/autoconf.h -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs -fno-strict-aliasing -fno-common -O2
-fomit-frame-pointer -m64 -mno-red-zone -mcmodel=kernel -pipe -fno-reorder-blocks -Wno-sign-compare -fno-asynchronous-unwind-tables -fun
it-at-a-time -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -Wdeclaration-after-statement -Wno-pointer-sign -I. -Iinclude -O4 -g -Wall -DBUILDING_T
ONEZONE -m64 -DSTANDALONE_ZAPATA -DZAPTEL_CONFIG="/etc/zaptel.conf" -DHOTPLUG_FIRMWARE -I/home/cestus/zaptel/src/zaptel-1.2.8//include
-I/home/cestus/zaptel/src/zaptel-1.2.8//include/oct6100api -DMODULE -D"KBUILD_STR(s)=#s" -D"KBUILD_BASENAME=KBUILD_STR(zaptel)" -D"KBUIL
D_MODNAME=KBUILD_STR(zaptel)" -c -o /home/cestus/zaptel/src/zaptel-1.2.8/zaptel.o /home/cestus/zaptel/src/zaptel-1.2.8/zaptel.c
I've figured out that the bit which causes the failure is "-include include/linux/autoconf.h", because autoconf.h just includes the "err_kernel_only" header automatically, which then slays the build process. And I've also discovered that the Zaptel devs are uber-leet. They've found the magical -O4 level in gcc. You know, the one above 3, where the supported optimization levels in gcc are -O, -Os, -O2 and -O3
Maybe you are looking for
-
Work centre capacity utilization
Dear guru , i have a work centre that always work in the same moment for 3 different production order. If my total daily available capacity is 11 hours for my 1 individual capacity is right that I assign to the work centre a capacity utilization of 3
-
Displaying a timeline on a panel
Hi everyone!! I am trying to develop a project management tool, so I need to know the best way of implementing a timeline (in months) to display on a JPanel. Basically, when the user selects a start date and duration of the project, I need a timeline
-
Now that I have subscribed to iTunes Match and synched my phone, I'm assuming that my 6.9GB of music and 2.3 GB of videos are stored in the cloud and accessible to my phone for listening or watching. Can I now delete them from my phone so that I reg
-
Hello there, We've got a problem with saving our design/file at this moment. The error describes: there are problems with the Adobe PDF-classification: an number is out of range... We're saving the file as CS6-version with PDF-compatible option selec
-
how do upload logo in ALV