Solved

jsp not running...

Posted on 2012-03-27
7
282 Views
Last Modified: 2012-06-27
I have CarBean.jsp at:
...Tomcat 5.0\webapps\begjsp-ch04\CarBean.jsp

Its content is:


<html>
      <head>
            <title>Using a JavaBean</title>
      </head>
      <body>
            <h2>Using a JavaBean</h2>
            <% myCar = new CarBean();%>
            I own a <%=myCar.getMake()%>
            <%myCar.setMake("Ferrari");%>
            Now I own a <%=myCar.getMake();%>
      </body>
</html>

---------------------
the associated CarBean class is compiled and put in the following folder:
C:\Program Files\Apache Software Foundation\Tomcat 5.0\webapps\begjsp-ch04\WEB-INF\classes

Its content is:

public class CarBean {

      public CarBean() {
      }

      private String make = "Ford";

      public String getMake() {

            return make;
      }

      public void setMake(String make) {


            this.make = make;

      }

}

----------------------------
I am using the following url to open this page:

http://localhost:8080/begjsp-ch04/CarBean.jsp

It fails. What is wrong with this? Can you please debug?

Thank you.
0
Comment
Question by:Mike Eghtebas
  • 5
7 Comments
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
you need the import statemne in the beginning of jsp
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
0
 
LVL 47

Expert Comment

by:for_yan
Comment Utility
try to put this at the top:
<%@ page language="java" import="CarBean" %>
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 47

Expert Comment

by:for_yan
Comment Utility
Once again go to examples application in tthe tomcat webapps folder and the go to jsp there - most of them use classes - chek out how they are imported, like in theis example for calculator for instance:

<HTML>
<!--  
  Copyright (c) 1999 The Apache Software Foundation.  All rights 
  reserved.
-->
<HEAD><TITLE> 
	Calendar: A JSP APPLICATION
</TITLE></HEAD>


<BODY BGCOLOR="white">

<%@ page language="java" import="cal.*" %>
<jsp:useBean id="table" scope="session" class="cal.TableBean" />

<%
	table.processRequest(request);
	if (table.getProcessError() == false) {
%>

<!-- html table goes here -->
<CENTER>
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
<TD ALIGN=CENTER> <A HREF=cal1.jsp?date=prev> prev </A>
<TD ALIGN=CENTER> Calendar:<%= table.getDate() %></TD>
<TD ALIGN=CENTER> <A HREF=cal1.jsp?date=next> next </A>
</TR>
</TABLE>

<!-- the main table -->
<TABLE WIDTH=60% BGCOLOR=lightblue BORDER=1 CELLPADDING=10>
<TR>
<TH> Time </TH>
<TH> Appointment </TH>
</TR>
<FORM METHOD=POST ACTION=cal1.jsp>
<%
	for(int i=0; i<table.getEntries().getRows(); i++) {
	   cal.Entry entr = table.getEntries().getEntry(i);	
%>
	<TR>
	<TD> 
	<A HREF=cal2.jsp?time=<%= entr.getHour() %>>
		<%= entr.getHour() %> </A>
	</TD>
	<TD BGCOLOR=<%= entr.getColor() %>>
	<%= entr.getDescription() %>
	</TD> 
	</TR>
<%
	}
%>
</FORM>
</TABLE>
<BR>

<!-- footer -->
<TABLE WIDTH=60% BGCOLOR=yellow CELLPADDING=15>
<TR>
<TD ALIGN=CENTER>  <%= table.getName() %> : 
		     <%= table.getEmail() %> </TD>
</TR>
</TABLE>
</CENTER>

<%
	} else {
%>
<font size=5>
	You must enter your name and email address correctly.
</font>
<%
	}
%>


</BODY>
</HTML>

Open in new window

0
 
LVL 47

Accepted Solution

by:
for_yan earned 500 total points
Comment Utility
Put this myCar.jsp (see below)  into webapps/examples

Put your CarBean.class into examples/WEB-INF/classes

and then
http://localhost:8080/examples/myCar.jsp

should work

Maybe you would need to reastrt Tomcat


<html>
      <head>
            <title>Using a JavaBean</title>
      </head>
      <body>
      <%@ page language="java" import="*" %>
      <jsp:useBean id="car" scope="session" class="CarBean" />


            <h2>Using a JavaBean</h2>
           
            I own a <%=car.getMake()%>
            <%car.setMake("Ferrari");%>
            Now I own a <%=car.getMake()%>
      </body>
</html>

Open in new window



output in the browser:

Using a JavaBean
I own a Ferrari Now I own a Ferrari 

Open in new window

0
 
LVL 27

Expert Comment

by:rrz
Comment Utility
eghtebas,   Did that solution really work for you ?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
Comment Utility
rrz@871311,

The input from for_yan was accurate. I had additional issues with my environment setup.

Thank you for the follow up

Mike
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

772 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now