• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

if the request parameter name matches the bean property name, ....

 
Nalaka Ariyarathna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please somebody help meee!!!

<<<<<< if the request parameter name matches the bean property name,you dont need to specify a value in the <jsp:setProperty> tag for that propery. >>>>>>
Head First Servlets & JSP -- page no:361

--------------------------------------- Form.html --------------------------------------------------------

<form action="result.jsp" method="get">Click Here<p>
Name : <input type="text" name="name">
<center>
<input type="submit">
</center>
</form>
-----------------------------------------------------------------------------------------------------

----------------------------------- result.jsp --------------------------------------------------------------------------

<jsp:useBean id="person" type="com.examples.Person" class="com.examples.Employe" >
<jsp:setProperty name="person" property="name" />
</jsp:useBean>
------------------------------------------------------------------------------------------------------------------------

------------------------------------------------------- JBoss [Morpheus] 5.0.0.GA ---------------------------------------------------------------

13:27:04,336 ERROR [[jsp]] Servlet.service() for servlet jsp threw exception
org.apache.jasper.JasperException: /result.jsp(20,0) useBean: Duplicate bean name: {0}
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:40)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:407)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:102)
at org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:619)
at org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1178)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2359)
at org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2409)
at org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2415)
at org.apache.jasper.compiler.Node$Root.accept(Node.java:495)
at org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2359)
at org.apache.jasper.compiler.Validator.validateExDirectives(Validator.java:1736)
at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:184)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:333)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:313)
at org.apache.jasper.compiler.Compiler.compile(Compiler.java:300)
at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:585)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:312)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:322)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:249)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)

----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this all you have in result.jsp ?
 
Nalaka Ariyarathna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry Sir, I thought that is the only important part.

This is my JSP

---------------------------------------------------------------------------------------------------------------------------------------------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="com.examples.Employe"%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here erererer drww</title>
</head>
<body>
<%--s<jsp:useBean id="person" class="com.examples.Person" scope="request"></jsp:useBean>--%>
<%--<jsp:useBean id="person" type="com.examples.Person" scope="request" class="com.examples.Employe"></jsp:useBean>--%>
<%--<jsp:useBean id="person" type="com.examples.Person" scope="request"></jsp:useBean>--%>
<%--<jsp:getProperty name="person" property="name"/>--%>

<!--<jsp:useBean id="person" type="com.examples.Person" class="com.examples.Employe">-->
<!-- <jsp:setProperty name="person" property="name" param="userName"/>-->
<!--</jsp:useBean>-->

<jsp:useBean id="person" type="com.examples.Person" class="com.examples.Employe" >
<jsp:setProperty name="person" property="name" />
</jsp:useBean>

<!--<jsp:getProperty name="person" property="name"/>-->

</body>
</html>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

These are HTML comments, but the JSP container will translate the JSP part of it. So you are already declaring a bean named "person" here.
Then you declare another one (the part without comments), where the error happens.

So remove those HTML comments, or change them into JSP comments.
 
Nalaka Ariyarathna
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it sir. Tested and it works fine.

I am Stunning of getting quick help of you sir. Thank you Christophe Verré and thank you The Big Moose Saloon.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
Nidhi Sar
Ranch Hand
Posts: 252
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Christophe Verré wrote:<!-- <jsp:useBean id="person" type="com.examples.Person" class="com.examples.Employe"> -->
These are HTML comments, but the JSP container will translate the JSP part of it. So you are already declaring a bean named "person" here.
Then you declare another one (the part without comments), where the error happens.

So remove those HTML comments, or change them into JSP comments.


Hmmmm... very interesting.

Quoting HFSJ -2nd ed (page 304)
"
<!-- HTML comment --> The container just passes this straight on to the client, where the browers interprets it as a comment
<%-- JSP comment --%> These are for the page developers, and just like java comments in a java source, they're stripped out of the translated page
"


So why are the HTML comments being even looked at by the container?

Thanks,
Nidhi
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2536
113
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nidhi,

So why are the HTML comments being even looked at by the container?

HTML comments are just like template text for the container, but have a meaning for the browser.

Regards,
Frits
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic