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.