Reputation: 145
I have a simple html page where I pass two values, a name (String
) & the number of nights (int
) to a jsp page. There I use a jsp:useBean
tag & a jsp:setProperty
tag. When I replaced <%= myRes.getName() %>
with <jsp:getProperty name="myRes" property="name">
it gives a long exception report. But when I reload the page twice it gives the correct output. The exception report is given below.
org.apache.jasper.JasperException: /hotel_jsp_bean_one.jsp(13,30) According to TLD, tag jsp:getProperty must be empty, but is not org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:41) org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407) org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:132) org.apache.jasper.compiler.Parser.parseBody(Parser.java:1631) org.apache.jasper.compiler.Parser.parseOptionalBody(Parser.java:1002) org.apache.jasper.compiler.Parser.parseGetProperty(Parser.java:905) org.apache.jasper.compiler.Parser.parseStandardAction(Parser.java:1132) org.apache.jasper.compiler.Parser.parseElements(Parser.java:1449) org.apache.jasper.compiler.Parser.parse(Parser.java:138) org.apache.jasper.compiler.ParserController.doParse(ParserController.java:239) org.apache.jasper.compiler.ParserController.parse(ParserController.java:102) org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:197) org.apache.jasper.compiler.Compiler.compile(Compiler.java:372) org.apache.jasper.compiler.Compiler.compile(Compiler.java:352) org.apache.jasper.compiler.Compiler.compile(Compiler.java:339) org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:594) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:344) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:391) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:334) javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
My bean class is :
package hotel;
public class Hotel
{
private String name;
private int nights;
public Hotel()
{
this.name = "<NOT SPECIFIED>";
this.nights = -1;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return this.name;
}
public void setNights(int nights)
{
this.nights = nights;
}
public int getNights()
{
return this.nights;
}
Then my first html page is :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotel Califona Reservation</title>
</head>
<body>
<h2 align="center">Welcom To The Hotel Califonia</h2>
<br/>
<br/>
<form method="post" action="hotel_jsp_bean_one.jsp">
<label>Enter your name : <input type="text" name="name"/>
<br/>
<label>How many nights : </label><select name="nights">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
<br/>
<input type="submit" name="submit" value="Reserve"/>
</form>
</body>
</html>
Then my final jsp page is :
<%@ page contentType="text/html; charset=utf-8" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hotel Califonia Reservation</title>
</head>
<jsp:useBean id="myRes" class="hotel.Hotel" scope="page"/>
<body>
<jsp:setProperty name="myRes" property="*"/>
<h3 style="color:#0000FF"><jsp:getProperty name="myRes" property="name"> is staying for <jsp:getProperty name="myRes" property="nights"> nights</h3>
</body>
</html>
Please forgive me for any inconvenient mistakes I've overlooked. Any help would be greatly appreciated. Thanks in advance.
Upvotes: 1
Views: 14323
Reputation: 403611
This is not valid:
<jsp:getProperty name="myRes" property="name"> is staying for <jsp:getProperty name="myRes" property="nights">
It should be:
<jsp:getProperty name="myRes" property="name"/> is staying for <jsp:getProperty name="myRes" property="nights"/>
Note the closing /
at the end of each getProperty.
Upvotes: 11
Reputation: 1
I ran into this problem today in a JSP/Servlets class. I believe that the solution to this is to put a / to close out the tag in your final JSP page.
I overlooked closing out the tag, and after putting the / in, my page worked flawlessly.
Upvotes: 0