Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet not compiling

 
shishir gupta
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am unable to compile my servlet. if i do not use requestURL() then it compiles. i have set my classpath as
.;D:\java\core\packages;D:\oracle\ora81\jdbc\lib\classes111.zip;d:\JSDK\lib\jsdk.jar;d:\j2ee1.3.1\lib\j2ee.jar;D:\jakarta-tomcat\lib\servlet.jar;D:\jboss-3.2.3\server\default\lib\javax.servlet.jar;

I am getting two errors when i compile this servlet:

D:\jboss-3.2.3\server\default\deploy\cpnm.war\WEB-INF\classes>javac TokenServlet.java
TokenServlet.java:22: cannot resolve symbol
symbol : method getRequestURL ()
location: interface javax.servlet.http.HttpServletRequest
String requestURLSame =req.getRequestURL().toString() + "?token=" +tokenID;
^
TokenServlet.java:23: cannot resolve symbol
symbol : method getRequestURL ()
location: interface javax.servlet.http.HttpServletRequest
String requestURLNew =req.getRequestURL().toString();
^
2 errors

import javax.servlet.http.*;
import java.util.*;
import java.io.*;

public class TokenServlet extends HttpServlet {
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,

IOException {
String tokenID=req.getParameter("tokenID");
res.setContentType("text/html");
PrintWriter out=res.getWriter();
out.println("<html><head><title>Tokens</title></head><body> ");

if(tokenID==null) {
Random rand=new Random();
tokenID=Long.toString(rand.nextLong());
out.println("<p> Welcome. A new token "+tokenID + " is now established</p>");
}
else {
out.println("<p> Welcome back. Your token is " +tokenID + ".</p>");
}

String requestURLSame =req.getRequestURL().toString() + "?token=" +tokenID;
String requestURLNew =req.getRequestURL().toString();

out.println("<p> Click <a href=" + requestURLSame + "> here</a> again to cont. browsing with

same identity.</p>");
out.println("<p> Otherwise, click <a href=" + requestURLNew + "></a> again to start with new

identity.</p>");
out.close();

}
}

Facing the same problem when I try to use getServletContextName (), getAttribute(). If I use getValue() my program compiles. I do not know where I am wrong. I am using JDK1.4 beta version, JBoss3.2.3 which supports latest Servlet specification.
Please help.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That sure sounds like a version conflict to me - did you every have a much older servlet library installed on that system?

Bill
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!