Farshid-Zaker
asked on
simple netbean jsp application
Hi,
This is a question from 2 days old java programmer! I want to create a simple jsp web application using net bean. here is the tasks I have done:
I created a jsp file. Here is its body. Its name is index.jsp.
<%@ page import = "HelloJava.HelloJavaBean" %>
<jsp:useBean id="helloJava" class="HelloJava.HelloJava Bean" scope="session"/>
<jsp:setProperty name="helloJava" property="*"/>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head><title>JSP Page</title></head>
<body>
<b>
<%= helloJava.GetAnswer() %>
</b>
</body>
</html>
************************** ********** ********** **
Then, I added a java class to filesystem, named HelloJavaBean.java :
import java.util.*;
public class HelloJavaBean {
int answer = 5;
/** Creates a new instance of HelloJavaBean */
public HelloJavaBean() {
}
public int GetAnswer()
{
return answer;
}
}
************************** ********** *****
I have trie to run this. But every time I got this error:
org.apache.jasper.JasperEx ception: Unable to compile class for JSP
C:\Documents and Settings\Farshid\.netbeans \3.6\jakar ta-tomcat- 5.0.19_bas e\work\Cat alina\loca lhost\hell ojava\org\ apache\jsp \index_jsp .java:6: package HelloJava does not exist
import HelloJava.HelloJavaBean;
^
I have tried to fix it by adding this block to web configuration file:
<servlet>
<servlet-name>HelloJava.in dex_jsp</s ervlet-nam e>
<servlet-class>HelloJava.i ndex_jsp</ servlet-cl ass>
</servlet>
but, nothing changed. I have <welcome-file-list> tag in my web configuration file.
Please tell me what to do.
Thanks,
Farshid
This is a question from 2 days old java programmer! I want to create a simple jsp web application using net bean. here is the tasks I have done:
I created a jsp file. Here is its body. Its name is index.jsp.
<%@ page import = "HelloJava.HelloJavaBean" %>
<jsp:useBean id="helloJava" class="HelloJava.HelloJava
<jsp:setProperty name="helloJava" property="*"/>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head><title>JSP Page</title></head>
<body>
<b>
<%= helloJava.GetAnswer() %>
</b>
</body>
</html>
**************************
Then, I added a java class to filesystem, named HelloJavaBean.java :
import java.util.*;
public class HelloJavaBean {
int answer = 5;
/** Creates a new instance of HelloJavaBean */
public HelloJavaBean() {
}
public int GetAnswer()
{
return answer;
}
}
**************************
I have trie to run this. But every time I got this error:
org.apache.jasper.JasperEx
C:\Documents and Settings\Farshid\.netbeans
import HelloJava.HelloJavaBean;
^
I have tried to fix it by adding this block to web configuration file:
<servlet>
<servlet-name>HelloJava.in
<servlet-class>HelloJava.i
</servlet>
but, nothing changed. I have <welcome-file-list> tag in my web configuration file.
Please tell me what to do.
Thanks,
Farshid
I dont really know if it matters, but isnt JavaBean convention to have the class like:
String answer
public void getAnswer()
{
}
String answer
public void getAnswer()
{
}
Argh, stupid submit on Enter :/
String answer
public void getAnswer()
{
this.answer;
}
public String setAnswer(String answer)
{
this.answer = answer;
}
String answer
public void getAnswer()
{
this.answer;
}
public String setAnswer(String answer)
{
this.answer = answer;
}
ASKER
Hi
petmagdy: package definition is already exist. I just forgot to copy it. Sorry.
Celdri: even if all the answer property is removed from class and jsp files, the error message remains unchanged! I think I should define the java file as a servlet for the project, or something likt that. I don't know too much about jsp and J2EE concepts.
Please provide me with the solution.
<Farshid/>
petmagdy: package definition is already exist. I just forgot to copy it. Sorry.
Celdri: even if all the answer property is removed from class and jsp files, the error message remains unchanged! I think I should define the java file as a servlet for the project, or something likt that. I don't know too much about jsp and J2EE concepts.
Please provide me with the solution.
<Farshid/>
Oh, and you dont have to mess with web.xml, jsp or beans arent servlets so you dont have
to map them or anything.
This: <jsp:useBean id="helloJava" class="HelloJava.HelloJava Bean" scope="session"/>
Will find or create the Bean for you.. and this:
<jsp:setProperty name="helloJava" property="*"/>
wont work because your hellojava bean doesnt have a property called *. (I think)
However
<jsp:setProperty name="helloJava" property="answer" value="5"/>
this will store the value 5 in the bean helloJava.
to map them or anything.
This: <jsp:useBean id="helloJava" class="HelloJava.HelloJava
Will find or create the Bean for you.. and this:
<jsp:setProperty name="helloJava" property="*"/>
wont work because your hellojava bean doesnt have a property called *. (I think)
However
<jsp:setProperty name="helloJava" property="answer" value="5"/>
this will store the value 5 in the bean helloJava.
Hmm, ok so are you using Tomcat?
if so, check that in your WEB-INF\classes folder
there is another folder called HelloJava and inside it
there must be a HelloJavaBean.class
if so, check that in your WEB-INF\classes folder
there is another folder called HelloJava and inside it
there must be a HelloJavaBean.class
ASKER
Yes, I'm usign Tomcat. In fact I'm using built in Tomcat of NetBeans IDE. I tried all your instructions. But nothing changed. I removed the servlet mapping. And there is that class in WEB-INF folder. But, the error is the same.
<Farshid/>
<Farshid/>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I solved my problem. I was defining Packages without creating folders of them. In fact I am using java with .NET experiences.
Thank you Ovi and Celdric
<Farshid/>
Thank you Ovi and Celdric
<Farshid/>
ASKER
I splitted points. Would you please provide me online free JSP tutorials?
Thanks a lot.
<Farshid/>
Thanks a lot.
<Farshid/>
There are plenty of good JSP tutorials out there, here are the ones that got me started:
http://www.apl.jhu.edu/%7Ehall/java/Servlet-Tutorial/
http://javaboutique.internet.com/resources/javaatwork/SnJSP.html
tag definitions: What you can do with JSP Power
http://java.sun.com/products/jsp/tags/11/tags11.html
Good luck!
http://www.apl.jhu.edu/%7Ehall/java/Servlet-Tutorial/
http://javaboutique.internet.com/resources/javaatwork/SnJSP.html
tag definitions: What you can do with JSP Power
http://java.sun.com/products/jsp/tags/11/tags11.html
Good luck!
ASKER
Thanks a lot
<Farshid/>
<Farshid/>
Thank you.
package HelloJava;
and then move the file HelloJavaBean.java from its location into an insider directory called HelloJava, be case sensitive
or
simply open ur jsp and modify
<%@ page import = "HelloJava.HelloJavaBean" %>
to
<%@ page import = "HelloJavaBean" %>