0

I am trying to use JSP pages on my desktop computer (Windows 10 64-bit) with the Apache Tomcat server. I write Java code all the time for applications on my PC only (hobby stuff), no issues.

I once had this JSP stuff working back in 2004 but it was so many computers ago that I no longer have the setups that worked. I researched this bug for 3 days and found identical questions dating back to 2004, yet I've done all the things mentioned but I still can't find the problem. Is it so obvious that I don't see it?

Here is everything I can think of to show:


This is the exact JSP page... file name is exact, with exact case: "testMath.jsp", in folder d:\apache-tomcat-9.0.58\webapps\mathJSP

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>

<%@page import="math2.MathServlet" %>
<jsp:useBean id="s2" class="math2.MathServlet" scope="session" />
<jsp:setProperty name="s2" property="*" />

<title>Test document</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
</head>

<body>
<a name="top"></a>
<div style="margin-left:0.3cm; margin-right:0.3cm">

<span style="font-family:arial; font-size:150%; position:relative; bottom:-3px">&infin;</span>

 <h2 style="text-align:center; color:#0000f0">< b>Test document< /b>< /h2>

 </div>
 </body>
 </html>

This is the servlet code, exactly:

It has the explicit default constructor with no arguments, and it is public.

This is the compilation command in the DOS/command window: It puts the class file in the location as shown in the image.

javac MathServlet.java -cp /apache-tomcat-9.0.58/lib/servlet-api.jar -d /apache-tomcat-9.0.58/webapps/WEB-INF/classes

So the class folder/file path/name is /apache.../webapps/WEB-INF/classes/math2/MathServlet.class

package math2;

import javax.servlet.http.*;

public class MathServlet
{
    public  MathServlet()
    { }

    public  String  dummyFunc()>
    {
        return "xxxxx";
    }
}

These are the relevant environment variables: ** Is my Java version a problem? See JAVA_HOME and JAVA_JRE

CATALINA_HOME=D:\apache-tomcat-9.0.58

CLASSPATH=d:/apache-tomcat-9.0.58/webapps/WEB-INF/classes;d:/apache-tomcat-9.0.58/lib/jsp-api.jar
  • NOTE: The CLASSPATH did not originally include 'jsp-api.jar'. I read somewhere that it may be needed. It does not help. So the original CLASSPATH was

      CLASSPATH=d:/apache-tomcat-9.0.58/webapps/WEB-INF/classes
    

    CommonProgramFiles=C:\Program Files\Common Files CommonProgramFiles(x86)=C:\Program Files (x86)\Common Files CommonProgramW6432=C:\Program Files\Common Files

    JAVA_HOME=C:\Program Files\Java\jdk1.8.0_321 JAVA_JRE=C:\Program Files\Java\jre1.8.0_321

    Path=d:;C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0;C:\WINDOWS\System32\OpenSSH;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\dotnet;C:\Program Files\Java\jdk1.8.0_321\bin

    ProgramData=C:\ProgramData ProgramFiles=C:\Program Files ProgramFiles(x86)=C:\Program Files (x86) ProgramW6432=C:\Program Files


After entering the URL in the browser (Chrome, latest version),

URL = http://localhost:8080/mathJSP/testMath.jsp ... I get the page below:

HTTP Status 500 – Internal Server Error
Type Exception Report

Message /testMath.jsp (line: [6], column: [0]) The value for the useBean class attribute [math2.MathServlet] is invalid.

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: /testMath.jsp (line: [6], column: [0]) The value for the useBean class attribute [math2.MathServlet] is invalid.
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41)
[shortened]

Note The full stack trace of the root cause is available in the server logs.


Then after doing page-reload, i.e. CTRL-R, I get this:

HTTP Status 500 – Internal Server Error Type Exception Report

Message org.apache.jasper.JasperException: java.lang.ClassNotFoundException: org.apache.jsp.testMath_jsp

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.apache.jasper.JasperException: org.apache.jasper.JasperException: 
java.lang.ClassNotFoundException: org.apache.jsp.testMath_jsp


[shortened]

Note The full stack trace of the root cause is available in the server logs.


Updated servlet:

package math2;

// import java.io.Serializable;
import javax.servlet.http.*;

public class MathServlet ///  implements Serializable
{
    public  MathServlet()
    { }


    private int id;
    private String name;


    public int getId() {
        return id;
    }
    public void setId( int id ) {
        this.id = id;
    }
    public String getName() {
        return name;
    }
    public void setName( String name ) {
        this.name = name;
    }
}
MathWhiz
  • 21
  • 3
  • I think you should try a simple bean that conforms to the JavaBean conventions. See https://stackoverflow.com/questions/3295496/what-is-a-javabean-exactly#:~:text=A%20JavaBean%20is%20a%20Java,public%20setter%20and%20getter%20methods Also, check out the JavaBean specification. – rickz Mar 07 '22 at 19:41
  • Thanks, I forgot those things. added them but unfortunately, still same error. – MathWhiz Mar 07 '22 at 21:15
  • Can you get a simple HelloWorld. jsp to run? Why do you call your bean a Servlet? They are two different things. Just make a simple test bean Also, in your JSP remove the page directive import. The useBean tag will find the class on its own. – rickz Mar 07 '22 at 23:32
  • @rickz, thank you again: good second question. That must the root of my problem. The Java program is a servlet, not a bean. Not sure why I had bean code there, I probably found that way to access the class name which is all I want. – MathWhiz Mar 08 '22 at 18:42

1 Answers1

0

I have not been able to resolve this issue after removing bean stuff. No clue why.... examined the work file tomcat uses and still no clarity. I am not going to pursue any further. Thanks for the help.

MathWhiz
  • 21
  • 3