Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

help error importing own package and class

 
Sahil Ji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
package com.example.web;

import com.example.model.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class Showbeer extends HttpServlet
{
public void doPost(HttpServletRequest request,HttpServletResponse response) throws IOException, ServletException
{

String color=request.getParameter("color");
BeerExpert expert=new BeerExpert();
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println("Selected color is :"+color);

ArrayList list=expert.getBrands(color);
Iterator it=list.iterator();

while(it.hasNext())
{
out.println(it.next());
}

}
}





package com.example.model;

import java.util.*;

public class BeerExpert
{
ArrayList list;

public BeerExpert()
{
list=new ArrayList();
}

List getBrands(String color)
{
if(color.equalsIgnoreCase("black"))
{
list.add("Old Monk");
list.add("Budvizer");
}
else
if(color.equalsIgnoreCase("green"))
{
list.add("Sprite");
list.add("Limca");
}
else
if(color.equalsIgnoreCase("yellow"))
{
list.add("RoyalStag");
list.add("old Monk");
}
else
if(color.equalsIgnoreCase("White"))
{
list.add("WhiteMischif");
list.add("Soda");
}
else
{
list.add("Antiquity");
list.add("Mecdonalds");
}

return list;
}


}



Compiler Error :
F:\Learning Servlets\beer-v1>javac -d classes src\com\example\web\Showbeer.java

src\com\example\web\Showbeer.java:3: package com.example.model does not exist
import com.example.model.BeerExpert; //*(ITS NOT ABLE TO IMPORT THE CLASS BEER EXPERT)******
^
src\com\example\web\Showbeer.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.Showbeer
BeerExpert expert=new BeerExpert();
^
src\com\example\web\Showbeer.java:15: cannot find symbol
symbol : class BeerExpert
location: class com.example.web.Showbeer
BeerExpert expert=new BeerExpert();
^
****3 errors
 
Yalvin Duha
Ranch Hand
Posts: 41
Eclipse IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Perhaps you are forgetting to pass an appropriate classpath to the Java compiler, e.g.:

 
Sahil Ji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i tried but it wont help
 
Sahil Ji
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yalvin Duha wrote:Perhaps you are forgetting to pass an appropriate classpath to the Java compiler, e.g.:





Now its giving httpservlet package is not there please help yes above error remove but its not importing java.io and other java packages
 
Yalvin Duha
Ranch Hand
Posts: 41
Eclipse IDE Java Slackware
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then it means that the library jar file that contains HttpServlet implementation is not in your path. What web server or application server are you using? Tomcat? JBoss? GlassFish? Resin? You need to specify where the jar file is located if it's not already in your path, and depending on your OS, you should use ":" (Linux/Unix) or ";" (Windows) to separate each classpath, i.e. src\;path\to\servlet.jar.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic