I wonder, could one of you guru's please help me out. I'ev been stumped for a few hours with this. When my servlet compiles it can't find the bean even though the class is in the same directory. I am using jdk1.4 and both are in my /bin. My classpath is set up to find c:\tomcat\lib\servlet.jar. When I compile the servlet I get the following: <CODE> C:\jdk1.4\bin>javac UrlServlet.java UrlServlet.java:19: cannot resolve symbol symbol : class UrlBean location: class UrlServlet UrlBean bean; ^ UrlServlet.java:46: cannot resolve symbol symbol : class UrlBean location: class UrlServlet bean = new UrlBean(u); ^ 2 errors </CODE> My code is as follows: 1) for the servlet <CODE> import javax.servlet.*; import javax.servlet.http.*; import java.*; import java.net.*; import java.io.*; import java.util public class UrlServlet extends HttpServlet { public void service(HttpServletRequest request, HttpServletResponse response)throws IOException, ServletException { StringBuffer sb;
String s, st; String urlString; int index1,index3,index4, index5; int index2; String stTitle, stDesc, stDesc1, stDesc2, stDesc3;
response.setContentType("text/html"); PrintWriter out = response.getWriter(); urlString = request.getParameter("url"); URL u = new URL(urlString); UrlBean bean = new UrlBean(u);//PROBLEM sb = bean.getData(); .....etc </CODE> 2)For my bean which compiles without problem <CODE> import java.*; import java.net.*; import java.io.*; import java.util.*; public class UrlBean { String s; StringBuffer sb = new StringBuffer(); private StringBuffer data; BufferedReader br; public UrlBean() { } public UrlBean(URL u) { testUrl(u); } public void testUrl(URL u) { try { br = new BufferedReader(new InputStreamReader (u.openConnection().getInputStream())); while ( (s = br.readLine()) != null) { sb.append(s + "\n"); } } catch (IOException ee) { sb = null; } setData(sb); } public void setData(StringBuffer sb) { data = sb; } public StringBuffer getData() { return data; } } </CODE> I can't understand why such a fundemental thing is going wrong. I have also tried jdk1.2 I'em totally stumped and think its something really stupid. Thanks in advance
robert fennell
Greenhorn
Joined: Sep 05, 2001
Posts: 1
posted
0
Apologies if this is too obvious I think it may be that your classpath needs to include .; at the beginning. This will search the current directory first when compiling. I hope this helps.
Eric Howell
Ranch Hand
Joined: Nov 26, 2000
Posts: 63
posted
0
Originally posted by robert fennell: Apologies if this is too obvious I think it may be that your classpath needs to include .; at the beginning. This will search the current directory first when compiling. I hope this helps.
Thanks Robert. You're a star. I had overridden my classpath with one of my setup.bat's. I didn't think of checking them as I didn't realize I'ed done it.Consider this problem sorted. Thanks again mate
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.