Beans and JSP

M

Maxi

Where should I place my java file and JSP page in tomcat? I have installed
Tomcat here C:\jakarta-tomcat-4.1.24\.

Can anyone help me out. I have spend 2 days but I can get this simple (jsp &
beans) example to work. I am getting this error

Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac]
C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\examples\jsp\hej_jsp.java
:49: cannot resolve symbol
[javac] symbol : class JavaBean
[javac] location: class org.apache.jsp.hej_jsp
[javac] JavaBean catalystInfo = null;
[javac] ^
[javac]
C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\examples\jsp\hej_jsp.java
:51: cannot resolve symbol
[javac] symbol : class JavaBean
[javac] location: class org.apache.jsp.hej_jsp
[javac] catalystInfo = (JavaBean)
pageContext.getAttribute("catalystInfo", PageContext.SESSION_SCOPE);
[javac] ^
[javac]
C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\examples\jsp\hej_jsp.java
:54: cannot resolve symbol
[javac] symbol : class JavaBean
[javac] location: class org.apache.jsp.hej_jsp
[javac] catalystInfo = (JavaBean)
java.beans.Beans.instantiate(this.getClass().getClassLoader(), "JavaBean");
[javac] ^
[javac] 3 errors


-----------JavaBean.java---------------
import java.beans.*;

public class JavaBean extends Object implements java.io.Serializable {

private static String visionText;

public JavaBean() {
visionText = "Hello, World! Beans really work!";
}

public String getVisionText() {
return visionText;
}

public void setVisionText(String visionText) {
this.visionText = visionText;
}
}

--------------hej.jsp-----------------
<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<body>

<jsp:useBean id="catalystInfo" scope="session" class="JavaBean">
</jsp:useBean>
<p>Vision Text</p>
<form method="post" action="vision3.jsp">
<textarea name="visionText" cols="80" rows="25">
<jsp:setProperty name="catalystInfo" property="*" />
</textarea>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
 
A

Andy Flowers

The .class file should be placed in your web apps WEB-INF\classes directory.

The JSP file can be anywhere in the web app path (i.e. the root directory of
your web app and any directories below) that makes sense and is accessible
from the outside world apart from WEB-INF as this is hidden & protected.

Also as a matter of style, inheriting from Object is not necessary or used
much as it's implicit. Also having visionText as static means that ALL
accessing browsers will see the same value. This would probably not be what
was intended.

Maxi said:
Where should I place my java file and JSP page in tomcat? I have installed
Tomcat here C:\jakarta-tomcat-4.1.24\.

Can anyone help me out. I have spend 2 days but I can get this simple (jsp &
beans) example to work. I am getting this error

Generated servlet error:
[javac] Since fork is true, ignoring compiler setting.
[javac] Compiling 1 source file
[javac] Since fork is true, ignoring compiler setting.
[javac]
C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\examples\jsp\hej_jsp.java
:49: cannot resolve symbol
[javac] symbol : class JavaBean
[javac] location: class org.apache.jsp.hej_jsp
[javac] JavaBean catalystInfo = null;
[javac] ^
[javac]
C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\examples\jsp\hej_jsp.java
:51: cannot resolve symbol
[javac] symbol : class JavaBean
[javac] location: class org.apache.jsp.hej_jsp
[javac] catalystInfo = (JavaBean)
pageContext.getAttribute("catalystInfo", PageContext.SESSION_SCOPE);
[javac] ^
[javac]
C:\jakarta-tomcat-4.1.24\work\Standalone\localhost\examples\jsp\hej_jsp.java
:54: cannot resolve symbol
[javac] symbol : class JavaBean
[javac] location: class org.apache.jsp.hej_jsp
[javac] catalystInfo = (JavaBean)
java.beans.Beans.instantiate(this.getClass().getClassLoader(), "JavaBean");
[javac] ^
[javac] 3 errors


-----------JavaBean.java---------------
import java.beans.*;

public class JavaBean extends Object implements java.io.Serializable {

private static String visionText;

public JavaBean() {
visionText = "Hello, World! Beans really work!";
}

public String getVisionText() {
return visionText;
}

public void setVisionText(String visionText) {
this.visionText = visionText;
}
}

--------------hej.jsp-----------------
<%@page contentType="text/html"%>
<html>
<head><title>JSP Page</title></head>
<body>

<jsp:useBean id="catalystInfo" scope="session" class="JavaBean">
</jsp:useBean>
<p>Vision Text</p>
<form method="post" action="vision3.jsp">
<textarea name="visionText" cols="80" rows="25">
<jsp:setProperty name="catalystInfo" property="*" />
</textarea>
<input type="submit" name="Submit" value="Submit">
</form>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top