• Post Reply Bookmark Topic Watch Topic
  • New Topic

Help-javax.servlet.jsp does not exist

 
Tim Mahoney
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I have been an Oracle guy for a while and have been programming Java for just a couple of weeks now, so bare with me please. I am working though a .jsp tutorial and I am having problems compiling the following java code. To make it simple,I removed all the code below and tried to import the import javax.servlet.jsp.* and received the error -javax.servlet.jsp does not exist. Below are some specs. I hope that I provided enough info, please let me know if you need more. Do I need to download another file from sun or are my paths screwed up?

--I downloaded and installed the j2sdk1.4.2_07.
--I am able to compile and run regular java code, just having problems using the servlet code.
--I am using jpad to compile the program.
--My path=C:\j2sdk1.4.2_07\bin;C:\j2sdk1.4.2_07\lib\tools.jar;C:\ORANT\bin;C:\WINNT\system32;C:\WINNT;C:\WINNT\system32\nls;C:\WINNT\system32\nls\ENGLISH;C:\WNETFIN;C:\Program Files\Novell\ZENworks\;%SystemRoot%\system32\nls;%SystemRoot%\system32\nls\ENGLISH;C:\Blazix
--classpath=C:\Blazix\blazix.jar
-------------------------------------------------------------------
import java.io.*;
import java.io.IOException;
import javax.servlet.jsp.*;
import javax.servlet.jsp.tagext.TagSupport;
import javax.servlet.http.HttpServletRequest;

// Extend javax.servlet.jsp.tagext.TagSupport for implementations of
// tags that have no body or include the body verbatim.

public class CounterTag2 extends TagSupport {
private int count = 0;
private File counterFile = null;

// The doStartTag() method gets called at request time at the place
// where the element's start tag is found.

public int doStartTag() throws JspException {
try {
checkFile();
readCount();
// Need a JspWriter since we this method will be called from
// a JSP.
try{
JspWriter out = pageContext.getOut();
out.print(++count); // The output produced by the tag
}
catch(IOException ioe){
System.out.println("Error in custom tag counter:" + ioe);
}
}
catch(java.io.IOException ex) {
throw new JspException(ex.getMessage());
}
return SKIP_BODY; // doStartTag should return this constant when
} // the tag has no body. SKIP_BODY is inherited
// from javax.servlet.jsp.tagext.Tag

public int doEndTag() throws JspException { // Finish up
saveCount();
return EVAL_PAGE; // Continue with rest of JSP page
}
private void checkFile() throws JspException, IOException {
if(counterFile == null) {
counterFile = new File(getCounterFilename());
count = 0;
}
if(!counterFile.exists()) {
counterFile.createNewFile();
saveCount();
}
}
private String getCounterFilename() {
HttpServletRequest req = (HttpServletRequest)pageContext.
getRequest();
String servletPath = req.getServletPath();
String realPath = pageContext.getServletContext().
getRealPath(servletPath);

return realPath + ".cntr";
}
private void saveCount() throws JspException {
try {
DataOutputStream dout = new DataOutputStream(
new FileOutputStream(counterFile) );
dout.writeInt(count);
dout.close();
}
catch(Exception ex) {
throw new JspException(ex.getMessage());
}
}
private void readCount() throws JspException {
try {
DataInputStream din = new DataInputStream(
new FileInputStream(counterFile) );
count = din.readInt();
din.close();
}
catch(Exception ex) {
throw new JspException(ex.getMessage());
}
}
}
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65528
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The servlet API is not part of the base java installation.

What server are you intending to use? Tomcat? Resin? Other?

Implementations of the servlet API will be provided by these servers. Which jar file(s) you will need to add to your classpath will depend on which server you are going to use.
 
Tim Mahoney
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the quick response. I am running blazix. This was the suggested server in the following tutorial. http://www.jsptut.com/
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65528
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not familiar with Blazix. Poke around its distribution to find the jar files.

OR

Switch to Tomcat 5. You will find many more people who are familiar with Tomcat than Blazix who can give you help.
 
Tim Mahoney
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since I am just trying to compile the .java file, I dont see any reason to be concerened with the webserver. Correct me if Im wrong here. I believe I just need the jar file containing the servlet classes. Where can I get the needed servlet .jar file? I got the servlet-api.jar from the tomcat .zip file and set this jar file in my classpath. Any other suggestions?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65528
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the servlet-api.jar from the tomcat .zip file and set this jar file in my classpath.


That should do it.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!