Solved

simple netbean jsp application

Posted on 2004-10-20
14
1,923 Views
Last Modified: 2012-08-13
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.HelloJavaBean" 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.JasperException: Unable to compile class for JSP
C:\Documents and Settings\Farshid\.netbeans\3.6\jakarta-tomcat-5.0.19_base\work\Catalina\localhost\hellojava\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.index_jsp</servlet-name>
      <servlet-class>HelloJava.index_jsp</servlet-class>
    </servlet>

but, nothing changed.  I have <welcome-file-list> tag in my web configuration file.

Please tell me what to do.

Thanks,
Farshid
0
Comment
Question by:Farshid-Zaker
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 2
  • +1
14 Comments
 
LVL 13

Expert Comment

by:petmagdy
ID: 12358035
add this line to the start of class HelloJavaBean

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" %>

0
 
LVL 1

Expert Comment

by:Celdric
ID: 12358090
I dont really know if it matters, but isnt JavaBean convention to have the class like:

String answer

public void getAnswer()
{

}
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12358112
Argh, stupid submit on Enter :/
String answer

public void getAnswer()
{
        this.answer;
}

public String setAnswer(String answer)
{
      this.answer = answer;
}
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 4

Author Comment

by:Farshid-Zaker
ID: 12358199
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/>
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12358222
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.HelloJavaBean" 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.
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12358309
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
0
 
LVL 4

Author Comment

by:Farshid-Zaker
ID: 12358358
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/>
0
 
LVL 9

Accepted Solution

by:
Ovi earned 250 total points
ID: 12358501
Unless you have packed your application as a war file and uploaded into the webapps directory, under Tomcat, on server.xml configuration file, you need to setup the contect path of your application along with the filesystem path where your project files are located. Please see the allready deployed Tomcat applications configured into server.xml to see how needs to be done.

Hope this helps.
0
 
LVL 1

Assisted Solution

by:Celdric
Celdric earned 250 total points
ID: 12359244
We need to know where exactl is that missing class, and why cant your web-app find it.
We need someone who has used Netbeans IDE before..
Myself, I use MyEclipse with Eclipse, fast deployment plataform, although somewhat tricky
to use.

if youre looking into learning web-apps try this:
http://javaboutique.internet.com/tutorials/three/
0
 
LVL 4

Author Comment

by:Farshid-Zaker
ID: 12361465
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/>
0
 
LVL 4

Author Comment

by:Farshid-Zaker
ID: 12361508
I splitted points. Would you please provide me online free JSP tutorials?

Thanks a lot.
<Farshid/>
0
 
LVL 1

Expert Comment

by:Celdric
ID: 12362189
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!
0
 
LVL 4

Author Comment

by:Farshid-Zaker
ID: 12362269
Thanks a lot

<Farshid/>
0
 
LVL 9

Expert Comment

by:Ovi
ID: 12366811
Thank you.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
maven project in eclipse 11 60
doubleChar java challenge 7 129
Looking for some programs to resell or buy source codes 1 78
maven disable workspace resolution 1 41
Original post  on Monitis Blog. Web performance monitoring is broken into two camps: passive and active. Passive monitoring is defined as looking at real-world historical performance by monitoring actual log-ins, site hits, clicks, requests for…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question