|
-
Nov 6th, 2004, 03:35 PM
#1
Thread Starter
Dazed Member
Directory where Beans are stored?
According to this JSP book ive been reading.
Two WEB-INF subdirectories have special meaning: lib and classes. All application class files (such as servlet and custom tag library classes) must be stored in these two directories. The lib directory is for Java archive (JAR) files (compressed archives of Java class files). Class files that aren't packaged in JAR files must be stored in the classes directory.
Do i have to store my .class files in the following directory?
C:\Jakarta\jakarta-tomcat-5.0.28\webapps\ora\WEB-INF\classes
I also found this directory. 
C:\Jakarta\jakarta-tomcat-5.0.28\webapps\ora\doc\com\ora\jsp\beans
Thanks.
Last edited by Dilenger4; Nov 11th, 2004 at 02:45 PM.
-
Nov 8th, 2004, 03:16 PM
#2
You put your .class files into classes, but with regards to the directory structure, i.e. com.dilenger.someapp.PowerBean goes to classes/com/dilenger/someapp/PowerBean.class.
The directory you found is probably the documentation of classes in the com.ora.jsp.beans package. I assume there are only .html files in there.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 8th, 2004, 09:45 PM
#3
Thread Starter
Dazed Member
If i try and pull up a .jsp page that is has a standard tag embeded in it i get a http 404 error. The catalina variable has the path C:\Jakarta\jakarta-tomcat-5.0.28 and both the .jsp file that contains the html and <jsp:useBean> and the .class file that is the actual bean are in a directory with a path of C:\Jakarta\jakarta-tomcat-5.0.28\webapps\ora
The problem is with the <jsp:useBean id = "Message" class = "webapps\ora\Message"/> tag
I don't know too much about jsp but it looks like in the translation phase when the request comes in, the servlet container needs the path to the java compiler to compile the jsp into a servlet but before it does this the servlet container needs the information of where the jsp page is. Does this sound correct?
-
Nov 9th, 2004, 04:23 AM
#4
No, it doesn't. Unless your Tomcat is configured to serve a 404 on error. By default, Tomcat will serve a 500 (Internal Server Error) if it fails to compile or run a JSP, which would be the case if it couldn't find a bean.
Anyway, both the location of the .class file and the class attribute of the useBean tag are wrong. What's the fully qualified name of the bean?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 9th, 2004, 05:56 PM
#5
Thread Starter
Dazed Member
Yes i was getting http 500 errors also. Here is the fully qualified name of the bean. C:\Jakarta\jakarta-tomcat-5.0.28\webapps\ora\WEB-INF\classes\Message.java
And here is the <jsp:useBean> tag
<jsp:useBean id = "Message" class = "webapps\ora\WEB-INF\classes\Message"/>
The catalina servlet variable is configured with the path. C:\Jakarta\jakarta-tomcat-5.0.28
-
Nov 9th, 2004, 06:05 PM
#6
The fully qualified bean name is the same as the fully qualified class name and does not include any path information, but the package name as well as the class name. E.g. the standard String class has a FQN of java.lang.String. If your bean is in the global package then its FQN is Message, and the class attribute should simply contain "Message". If the bean's FQN is com.somecompany.utils.Message then it should be placed into ...webapps\ora\WEB-INF\classes\com\somecompany\utils\Message.class and the class attribute contains "com.somecompany.utils.Message".
Oh, btw, is your bean compiled? I ask because in your path you have Message.java, not .class. Beans, unlike JSP pages, aren't automatically compiled, you have to do that manually.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 10th, 2004, 02:17 AM
#7
Thread Starter
Dazed Member
Thanks for replying. I was on when you posted earlier but i had to run to get to a night class at uni.
No the bean is not compiled. I put the .java extension in to indicate that is was uncompiled. I assumed that beans are compiled during the translation phase(Converting the JSP page to a servlet and compiling the servlet form the translation phase.) which i guess isn't the case. Im gonna give this another wack and see what happens.
-
Nov 10th, 2004, 03:20 AM
#8
Only the .java file generated from the .jsp forms the servlet.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 10th, 2004, 01:45 PM
#9
Thread Starter
Dazed Member
Posted by CornedBee
If the bean's FQN is com.somecompany.utils.Message then it should be placed into ...webapps\ora\WEB-INF\classes\com\somecompany\utils\Message.class and the class attribute contains "com.somecompany.utils.Message".
I just dropped the bean into .....webapps\ora\WEB-INF\classes. Using <jsp:useBean id = "Message" class = "Message"/> within the jsp. I get a http 500 error. The problem is at line 11 which is the <jsp:useBean> tag again.
Code:
org.apache.jasper.JasperException: Unable to compile class for JSP
An error occurred at line: 11 in the jsp file: /TestJSP.jsp
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\ora\org\apache\jsp\TestJSP_jsp.java:52: cannot resolve symbol
symbol : class Message
location: class org.apache.jsp.TestJSP_jsp
Message Message = null;
^
An error occurred at line: 11 in the jsp file: /TestJSP.jsp
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\ora\org\apache\jsp\TestJSP_jsp.java:54: cannot resolve symbol
symbol : class Message
location: class org.apache.jsp.TestJSP_jsp
Message = (Message) _jspx_page_context.getAttribute("Message", PageContext.PAGE_SCOPE);
^
An error occurred at line: 11 in the jsp file: /TestJSP.jsp
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\ora\org\apache\jsp\TestJSP_jsp.java:56: cannot resolve symbol
symbol : class Message
location: class org.apache.jsp.TestJSP_jsp
Message = new Message();
^
An error occurred at line: 16 in the jsp file: /TestJSP.jsp
Generated servlet error:
C:\Jakarta\jakarta-tomcat-5.0.28\work\Catalina\localhost\ora\org\apache\jsp\TestJSP_jsp.java:65: cannot resolve symbol
symbol : class Message
location: class org.apache.jsp.TestJSP_jsp
out.write(org.apache.jasper.runtime.JspRuntimeLibrary.toString((((Message)_jspx_page_context.findAttribute("Message")).getMessage())));
^
4 errors
-
Nov 10th, 2004, 02:52 PM
#10
This is strange.
You shouldn't use the same name as the class has for the bean id (use a lowercase starting letter, "message"), but that's not the source of the error.
Can you show me the first few lines of the bean source?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 10th, 2004, 07:12 PM
#11
Thread Starter
Dazed Member
Yeah for the bean id i wasent sure what is acceptable to use. I haven't come across anything that specifies what kind of conventions to use for the id. Like if it shouldn't be the same name as the class attribute value. But i found out that is not the source of the problem as you also know.
I didn't think precompilation of a bean was needed because from all of the bean examples i have looked at thus far they contain no main methods. So how then are they precompiled? I just added in the main method into one of my test beans then compiled it.
Code:
import java.io.*;
public class Message implements Serializable{
public static void main(String[] args){}
private String message;
public Message(){}
public void setMessage(String message){
this.message = message;
}
public String getMessage(){
return message;
}
}
-
Nov 10th, 2004, 10:36 PM
#12
Thread Starter
Dazed Member
Im not so sure that precompilation of Java Beans are required. According to the following it is seems that when a browser requests a .jsp page that has the <jsp:useBean> embeded in it in an instance of the bean is created.
"The <jsp:useBean> action is one of the JSP standard actions (identified by the jsp prefix).The action creates an instance of the bean class specified by the class attribute and associates it with the name specified by the id attribute. The name must be unique in the page and be a valid Java variable name; it must start with a letter and can't contain special characters such as dots, plus signs, etc."
-
Nov 11th, 2004, 03:00 AM
#13
That means that the .class file is located and loaded, and that then an instance is created of the class within.
Don't forget: Beans are just simple Java classes that follow specific conventions, nothing else. Look at the .java file that is generated from your code.
<useBean id="message" class="Messag" />
translates to something like
Message message = new Message();
in the generated code. This means that the Message class must be there. You have to precompile it:
javac Message.java
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 11th, 2004, 01:16 PM
#14
Thread Starter
Dazed Member
I don't think the problem is with compilation because the .java file has been compiled into a .class file for the last couple of days. The problem must be somthing else.
-
Nov 11th, 2004, 02:25 PM
#15
Thread Starter
Dazed Member
Got it.
<jsp:useBean id = "message" class = "com.MyCompany.Beans.Message"/>
Code:
package com.MyCompany.Beans;
import java.io.*;
public class Message implements Serializable{
public static void main(String[] args){}
private String greeting = "Hello!" ;
public Message(){}
public String getGreeting(){
return greeting;
}
}
-
Nov 11th, 2004, 02:27 PM
#16
Err, so it forced you to use a package - or had it been in a package all along?
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Nov 11th, 2004, 02:32 PM
#17
Thread Starter
Dazed Member
What makes no sense is when the bean is stored in directories off of the classes directory and you provide the package statement such as
package com.MyCompany.Beans; and <jsp:useBean id = "message" class = "com.MyCompany.Beans.Message"/> everything works fine. But if you just drop the class file into the classes directory and use no package declaration and use the following tag <jsp:useBean id = "message" class = "Message"/> nothing works.
C:\Jakarta\jakarta-tomcat-5.0.28\webapps\ora\WEB-INF\classes\com\MyCompany\Beans
-
Nov 11th, 2004, 02:35 PM
#18
Thread Starter
Dazed Member
Yeah i think bean conventions are some how enforced to make you use packages.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|