• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

When servlet compiles it can't find bean

 
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 63
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
When it is used for evil, then watch out! When it is used for good, then things are much nicer. Like this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic