dcsimg
Wrong results from TC4.0.2 and TC3.3a
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   charles_so
Posted On:   Sunday, February 17, 2002 07:13 PM

I tried for a few days but couldn't figure out what is wrong... This Javabean, MyBean.java: public class MyBean implements java.io.Serializable { private String firstName; public MyBean() { } public String getFirstName() { return firstName; } public void setFirstName(String name) { firstName = name; } } And the JSP is: <%@page import="MyBean" %>; <%jsp:useBean id="Person" class="MyBean" scope="request"/%> <%= Person.setFirstName("John") %>    More>>


I tried for a few days but couldn't figure out what is wrong...


This Javabean, MyBean.java:


			
public class MyBean implements java.io.Serializable {

private String firstName;

public MyBean() {
}

public String getFirstName() {
return firstName;
}

public void setFirstName(String name) {
firstName = name;
}
}



And the JSP is:


			
<%@page import="MyBean" %>;
<%jsp:useBean id="Person" class="MyBean" scope="request"/%>


<%= Person.setFirstName("John") %>


<%= Person.getFirstName() %>



The trouble is, I'll get this error when run under both TC3.3a and TC4.0.2



			
org.apache.jasper.JasperException: Unable to compile /Applications/jakarta-tomcat-3.3a/work/DEFAULT/mine/CallBean_3.java:80: Incompatible type for method. Can't convert void to java.lang.Object.
out.print( Person.setFirstName(new String("John")) );



Why is this error? I can't figure out what is wrong with it...

   <<Less

Re: Wrong results from TC4.0.2 and TC3.3a

Posted By:   Anonymous  
Posted On:   Monday, February 18, 2002 01:28 AM

Your setter does not return any value (void) so the println method (that is the compiled version of the <%= ... %> tag, cannot generate a string to print out.

If you want to just assign a value to a bean, you can use the jsp:setProperty or use the simple scriplet:

<% Person.setFirstName("John"); %>


Regards

About | Sitemap | Contact