Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

new to JSP

Posted on 2003-02-27
7
Medium Priority
?
184 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
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
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 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The article explains the process to deploy a Self-Service password reset portal I developed a few years ago. Hopefully, it will prove useful to someone.  Any comments, bug reports etc. are welcome...
If you need to complete a Physical to Virtual (P2V), Virtual to Virtual (V2V) conversion to a VMware product (VMware Workstation, Player or VMware vSphere (ESXi) ) for FREE, then there is some good news...
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Kernel Data Recovery is a renowned Data Recovery solution provider which offers wide range of softwares for both enterprise and home users with its cost-effective solutions. Let's have a quick overview of the journey and data recovery tools range he…
Suggested Courses

569 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