aspose file tools
The moose likes Servlets and the fly likes package problems Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Servlets
Reply Bookmark "package problems" Watch "package problems" New topic
Author

package problems

Dan Caylor
Greenhorn

Joined: Jan 16, 2001
Posts: 11
I am following an example in a book I bought. It's called Core Servlets and Java Server Pages. Here is the example;
<HTML>
<HEAD>
<TITLE>The import Attribute</TITLE>
<LINK REL=STYLESHEET
HREF="JSP-Styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<H2>The import Attribute</H2>
<%-- JSP page directive --%>
<%@ page import="java.util.*,coreservlets.*" %>
<%-- JSP Declaration (see Section 10.4) --%>
<%!
private String randomID() {
int num = (int)(Math.random()*10000000.0);
return("id" + num);
}
private final String NO_VALUE = "<I>No Value</I>";
%>
<%-- JSP Scriptlet (see Section 10.3) --%>
<%
Cookie[] cookies = request.getCookies();
String oldID =
ServletUtilities.getCookieValue(cookies, "userID", NO_VALUE);
String newID;
if (oldID.equals(NO_VALUE)) {
newID = randomID();
} else {
newID = oldID;
}
LongLivedCookie cookie = new LongLivedCookie("userID", newID);
response.addCookie(cookie);
%>
<%-- JSP Expressions (see Section 10.2) --%>
This page was accessed at <%= new Date() %> with a userID
cookie of <%= oldID %>.
</BODY>
</HTML>
With the books you create your own package where you store your servlets and class files from the book (the coreservlets package). I am now on part 2 and I'm learning about Directives in JSP. I came across a problem when I tried to run the code above. It gives me an error stating that it cannot find the coreservlets package. Right before this jsp page it warns of where to place your servlets for this to work when you are importing your own classes from a package you made. I followed these directions but it still won't import.
I know it's a very simple problem, but I don't want simple things like this to hang be up when I start developping. If anyone could help I'd be appreciative : )
(Also, the ServletUtilities, and LongLivedCookie class and java files are within the coreservlets package.)
Dan Caylor http://www.thinkdan.com
dan@thinkdan.com
triveni sangam
Greenhorn

Joined: Jan 12, 2001
Posts: 11
HI, I am not very sure, but I think u have to add the path of ur package to ur classpath. That should solve ur problem.
Dan Caylor
Greenhorn

Joined: Jan 16, 2001
Posts: 11
How would I do that?
Dan Caylor
Greenhorn

Joined: Jan 16, 2001
Posts: 11
Nevermind, must of had a brain fart...
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi,
I faced the same problem. Its a package problem. Assuming you are using tomcat, you have to place your Tag handler's ".class" file in WEB-INF/classes directory of your application, ie what ever you have named your application, under the Webapps directory. Let's say you have placed your jsp/tag descriptor file under examples/jsp directory, then your .class file of the tag handler class should go in the WEB-INF\classes(\webapps\examples\WEB-INF\classes) directory of examples application and not under other applications directory.
Hope this helps!

Dan Caylor
Greenhorn

Joined: Jan 16, 2001
Posts: 11
Hi guys, thanks for the help so far, but I still can't get it. I added the package dir to the classpath, I went back in the book and it says you have to do that, but it still doesn't work.
I have Tomcat installed in C:/jakarta-tomcat, this is where I put my java and class files. I can run single servlet files normally even when they are in the coreservlets package and I've always been able to as well.
This is where the servlet files are:
c:/jakarta-tomcat/webapps/ROOT/WEB-INF/classes/coreservlets
and this is where the JSP files are:
c:/jakarta-tomcat/webapps/JSP-Code
I have multiple java files that are in the
c:/jakarta-tomcat/webapps/ROOT/WEB-INF/classes/coreservlets
directory and I can't get any of them to compile. They all need for you to compile other java files, but when you try to comile them, it says it can't find package coreservlets...
I'm really clueless cause I'm just starting out.
Xinbo Cheng
Greenhorn

Joined: Jan 05, 2001
Posts: 15
Hi, I do not know what your problem is but I was having trouble with packages myself. I thought I was doing everything right but
the package won't compile for me. It turned out that I appended too many things on my classpath and some of them got cut off, so
check your classpath to see whether it is really there before doing anything else.
Xinbo
Marius Holm
Ranch Hand

Joined: Sep 11, 2000
Posts: 84
Cindy Crawford?!?
I'm impressed that you have the time for Java programming along with your modelling carreer.
Keep it up!
Marius
Cynthia Yao
Ranch Hand

Joined: Nov 06, 2000
Posts: 92

If your problem is that the jsp page can not find the package, then it may because your jsp pages is not in the right place. It should be tomcat\webapps\root\.jsp
Viji Bharat
Ranch Hand

Joined: Sep 18, 2000
Posts: 101
Hi:
Include ...\web-inf\classes directory in your classpath. Now, the code should compile.
Viji
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: package problems
 
Similar Threads
Struts2-json plugin not serializing action class to json
Cookie problem
cookie and jsp
cookie setDomain problem.
how to set Persistant Cookies