Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

package problems

 
Dan Caylor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How would I do that?
 
Dan Caylor
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nevermind, must of had a brain fart...
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi:
Include ...\web-inf\classes directory in your classpath. Now, the code should compile.
Viji
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic