Solved

jsp not running...

Posted on 2012-03-27
7
290 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
ID: 37774418
you need the import statemne in the beginning of jsp
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37774421
0
 
LVL 47

Expert Comment

by:for_yan
ID: 37774438
try to put this at the top:
<%@ page language="java" import="CarBean" %>
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 47

Expert Comment

by:for_yan
ID: 37774473
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
ID: 37774546
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
ID: 37777325
eghtebas,   Did that solution really work for you ?
0
 
LVL 34

Author Comment

by:Mike Eghtebas
ID: 37780410
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
tomcat administrtor 12 61
hibernate example for saving data 19 57
Chrome and Firefox Java 5 52
ejb mdb examples 1 10
For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

828 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