Link to home
Start Free TrialLog in
Avatar of benk-master-flash
benk-master-flash

asked on

Submit BOOLEAN type to Java Bean using FORM -- getting type mismatch

gettig error from following code... pls help

***** BEANTEST.JSP*********

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head><title>Let's Test a Bean</title></head>
<body bgcolor=white text=black link=black vlink=black>

<%
      if (request.getParameter("reload") != null) {
%>
      <jsp:useBean id="formHandler" class="coreservlets.beans.UserBean" scope="session" />

      <jsp:setProperty name="formHandler"
                         property="username"
                         value='<%= request.getParameter("username") %>' />

      <jsp:setProperty name="formHandler"
                         property="password"
                         value='<%= request.getParameter("password") %>' />

      <jsp:setProperty name="formHandler"
                         property="changed"
                         value='<%= request.getParameter("changed") %>' />
      
      <jsp:forward page="./Controller.jsp" />
            
<% } else { %>
      <center><b>WELCOME! -- Let's Test a Bean</b>
      <br>
      <form action='<%= response.encodeURL("BeanTest.jsp?reload=true") %>'>
            Username: <input type="text" name="username"><br>
            Password: <input type="password" name="password"><br>
            property isChanged() = boolean true<br>
            <input type="hidden" name="changed" value=true><br>
            <input type="submit" name="reload" value="Reload" >
      </form>      
      </center>
<% } %>

</body>
</html>

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: argument type mismatch
      org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:665)
      org.apache.jsp.BeanTest_jsp._jspService(BeanTest_jsp.java:75)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

root cause

java.lang.IllegalArgumentException: argument type mismatch
      sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      java.lang.reflect.Method.invoke(Method.java:324)
      org.apache.jasper.runtime.JspRuntimeLibrary.handleSetProperty(JspRuntimeLibrary.java:663)
      org.apache.jsp.BeanTest_jsp._jspService(BeanTest_jsp.java:75)
      org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
      org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
      org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
      org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
      javax.servlet.http.HttpServlet.service(HttpServlet.java:802)

note The full stack trace of the root cause is available in the Apache Tomcat/5.0.28 logs.
A

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">
 
<%@ page import="java.util.*" %>
<jsp:useBean id="formHandler" class="coreservlets.beans.UserBean" scope="session"/>

**** CONTROLLER.JSP *******
<html>
<head>
<title>Using jsp:setProperty</title>
</head>

<body>
      <center>
            <b>Page has been forwarded</b><br>
            username = <jsp:getProperty name="formHandler" property="username"/><br>
            password = <jsp:getProperty name="formHandler" property="password"/><br>
            changed = <jsp:getProperty name="formHandler" property="changed"/><br>
            <b>Horray it worked!</b>
      </center>
</body>
</html>

***** USERBEAN.JAVA ********

package coreservlets.beans;

import java.util.*;

/** use bean to represent DB user */

public class UserBean {
      
      private String username;
      private String password;
      private boolean changed;
      
      public String getUsername() {
            return(username);
      }
      
      public String getPassword() {
            return(password);
      }
      
      public boolean isChanged() {
            return(changed);
      }
      
      public void setUsername(String username) {
            this.username = username;
      }
      
      public void setPassword(String password) {
            this.password = password;
      }
      
      public void setChanged(boolean changed) {
            this.changed = changed;
      }
      
}
Avatar of benk-master-flash
benk-master-flash

ASKER

c'mon, read the code and help me out
Avatar of Ryan Chong
maybe try change:

public void setChanged(boolean changed) {
          this.changed = changed;
     }

to:

public void setChanged(string changed) {
          this.changed = (changed.equalsIgnoreCase("true"))?true:false;
     }

?
went through that, and the server responds
rg.apache.jasper.JasperException: Can't find a method to write property 'changed' of type 'boolean' in a bean of type 'coreservlets.beans.UserBean'
opps, should it be:

public void setChanged(String strchanged) {
          this.changed = (strchanged.equalsIgnoreCase("true"))?true:false;
     }
ASKER CERTIFIED SOLUTION
Avatar of rrz
rrz
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
or
<jsp:setProperty name="formHandler" property="*"/>
The points should have been split, siliconeagle's solution should work as well.    rrz