How to call Java Class from JSP page?


#1

Hi All,

I am new to c9. I created a Openshift JBoss application server & imported into C9 via GitHub.
I have a simple Java class in Main\Java\initial.class.

public class initial {


	public static void main(String[] args) {

		String prn = disp();
		System.out.println(prn);
	}

    public static String disp()
        {
        String str=" JAVARANCH ";
        return str;
    }
}

I have a jsp page called from index.html, I am just trying to display the variable ‘prn’ in the jsp page.

<HEAD>
	<TITLE>JBossAS7 JSP snoop page</TITLE>
	<%@ page import="javax.servlet.http.HttpUtils,java.util.Enumeration" %>
	<%@ page import="java.lang.management.*" %>
	<%@ page import="java.util.*" %>
	<%@ page import="initial" %>
</HEAD>
<BODY>

<H1>WebApp JSP Snoop page</H1>
<img src="images/jbosscorp_logo.png">

<h2>JVM Memory Monitor</h2>
<input type="text" name="text1" size="100" value="<%=prn%>">

But, I am getting below error at the JSP page:

org.apache.jasper.JasperException: Unable to compile class for JSP: 

An error occurred at line: 10 in the generated java file
The import initial cannot be resolved

An error occurred at line: 15 in the jsp file: /snoop.jsp
prn cannot be resolved to a variable
12: <img src="images/jbosscorp_logo.png">
13: 
14: <h2>JVM Memory Monitor</h2>
15: <input type="text" name="text1" size="100" value="<%=prn%>">
16:  
17: <table border="0" width="100%">
18:  

How do I interact with a Java class from my JSP?
thanks…