Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem importing a model class in a servlet

 
Rucha Gandhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am fairly new to servlets and JSPs, trying to get a hang of it by building a small web app. I am trying to import the model class into my servlet, but its not compiling, saying the package does not exist. I don't know what's causing this error. i've done everything right as far as I know by declaring correct packages in the servlet and the model. when I compiled the model class, it generated the required directory structure too.

suggestions would be appreciated. well, actually its a problem related to packages, but I am posting it here...someone would've faced the same problem sometime.
 
Choon-Chern Lim
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can you dump the exception log here?
 
Jignesh Patel
Ranch Hand
Posts: 626
Mac
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
saying the package does not exist

It is fairly simple, required package is not in your classpath.
 
Choon-Chern Lim
Ranch Hand
Posts: 74
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way, it is a good idea to append ".;.." to the classpath.
 
Rucha Gandhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi again,

Thanks, but still showing the same error even after adding the package to the classpath.

C:\Rucha\Exercises\MyProjects\Ch_V1>javac -d classes src/com/example/web/ServletSelect.java
src/com/example/web/ServletSelect.java:3: package com.example.model does not exist
import com.example.model.*;
^
src/com/example/web/ServletSelect.java:23: cannot resolve symbol
symbol : class ServletExpert
location: class com.example.web.ServletSelect
ServletExpert be = new ServletExpert();
^
src/com/example/web/ServletSelect.java:23: cannot resolve symbol
symbol : class ServletExpert
location: class com.example.web.ServletSelect
ServletExpert be = new ServletExpert();
^
3 errors

ServletExpert is the model which I am trying to import in ServletSelect.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Rucha Gandhi:
... adding the package to the classpath.

Doesn't sound right.

Where are your source files?
Where are your classfiles?
What exactly is in your classpath?

 
Rucha Gandhi
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys, it worked finally
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!