?
Solved

new to JSP

Posted on 2003-02-27
7
Medium Priority
?
181 Views
Last Modified: 2010-04-01
Hello everyone,
   I have this problem and I think its a real simple one, but I dont know how to solve this. I have a JSP file as follows:

------------
JSP FILE:
<%@page contentType="text/html"%>
<%@ page language="java" %>
<jsp:useBean id="ts" class="Test" scope="session"/>
<html>
<head><title>ATOS</title></head>
<body>

<%    
   
    String name = request.getParameter( "command" );
    out.println(name);
    ts.printIt();
%>


</body>
</html>
----------
I need to call on some functions (Methods) of another Java file (Class) from this JSP. As you can see that I have this
<jsp:useBean id="ts" class="Test" scope="session"/> tag. BUT IT DOESNT WORK !!!

I get the following error when I try to run it through a web browser:

org.apache.jasper.JasperException: Unable to compile class for JSP
---------
ERROR:
An error occurred at line: 4 in the jsp file: /invoke.jsp

Generated servlet error:
    [javac] Compiling 1 source file

C:\jakarta-tomcat-4.1.18\work\Standalone\localhost\Atos\invoke_jsp.java:44: cannot resolve symbol
symbol  : class Test  
location: class org.apache.jsp.invoke_jsp
      Test ts = null;
      ^
and so on ....
-------
I am running TOMCAT as my server and this class file "Test"  I have it under the TOMCAT_HOME\webapps\TESTAPP\WEB-INF\classes directory.

What am I doing wrong ???
Thanks in advance for your help.
Adil

0
Comment
Question by:AdilK
[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
7 Comments
 
LVL 28

Expert Comment

by:rrz
ID: 8035026
Try putting your bean in a package.
and use
<jsp:useBean id="ts" class="yourpackage.Test" scope="session"/>
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8035226
is there a package name for Test?

make sure you import it too.

<%@ page import="Test" %>

CJ
0
 

Author Comment

by:AdilK
ID: 8036102
Thanks,
  I tried the package thing and now I get a diffrent error!

org.apache.jasper.JasperException: test.Test.printIt()Ljava/lang/String;

I changed my JSP Page as follows:
----------
<%@page contentType="text/html"%>
<%@ page language="java"%>
<jsp:useBean id="t" class="test.Test" scope="session"/>

<html>
<head><title>ATOS</title></head>
<body>
<%    
   
    String name = request.getParameter( "command" );
    out.println(name);
%>
<br>
<%  out.println("\n Did It");%>
<br>
<%= t.printIt()%>
</body>
</html>
---------

and my Java file is as follows:
package test;
public class Test{

    public Test() {
    }
    public String printIt() {
        return("I am here");
 
    }
------
Seems like its having no problem looking and loading the Class file but now what is this error !!!!
Thanks
Adil
0
Independent Software Vendors: 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 19

Accepted Solution

by:
cheekycj earned 200 total points
ID: 8036248
add this:
<%@ page import="test.*" %>

and make sure when you compile your class file after adding package it is in the following directory:
TOMCAT_HOME\webapps\TESTAPP\WEB-INF\classes\test\Test.class

CJ

0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8036363
make sure this is the first line of your Test.java:
pacakge test;

re-compile Test.java and restart tomcat.
0
 
LVL 1

Expert Comment

by:Commodus2
ID: 8086948
Or instead of useBean you can use
<%
test.Test t = new test.Test();
.....
....
%>
..
<%=t.printIt()%>
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 8462326
Glad I could help and Thanx for the "A"

CJ
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The well known Cerber ransomware continues to spread this summer through spear phishing email campaigns targeting enterprises. Learn how it easily bypasses traditional defenses - and what you can do to protect your data.
Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month10 days, 7 hours left to enroll

765 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