Solved

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

Posted on 2004-11-01
1,033 Views
Last Modified: 2010-08-05
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;
      }
      
}
0
Question by:benk-master-flash
    7 Comments
     

    Author Comment

    by:benk-master-flash
    c'mon, read the code and help me out
    0
     
    LVL 48

    Expert Comment

    by: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;
         }

    ?
    0
     

    Author Comment

    by:benk-master-flash
    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'
    0
     
    LVL 48

    Expert Comment

    by:Ryan Chong
    opps, should it be:

    public void setChanged(String strchanged) {
              this.changed = (strchanged.equalsIgnoreCase("true"))?true:false;
         }
    0
     
    LVL 27

    Accepted Solution

    by:
    Try changing this  
         <jsp:setProperty name="formHandler"
                         property="changed"
                         value='<%= request.getParameter("changed") %>' />
    to this
         <jsp:setProperty
                                  name="formHandler"
                                  property="changed"
                                  param="changed" />
    I think that the conversions will done automatically then.       rrz
    0
     
    LVL 2

    Expert Comment

    by:siliconeagle
    or
    <jsp:setProperty name="formHandler" property="*"/>
    0
     
    LVL 27

    Expert Comment

    by:rrz
    The points should have been split, siliconeagle's solution should work as well.    rrz
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Suggested Solutions

    With the shift in today’s hiring climate (http://blog.experts-exchange.com/ee-blog/5-tips-on-succeeding-in-the-new-gig-economy/?cid=Blog_031816), many companies are choosing to hire freelancers to get projects completed efficiently and inexpensively…
    Sometimes Outlook might have problems sending a message. There may be various causes- corrupted PST, AV scanner etc. The message, instead of going to the Sent Items folder, sits in the Outbox indefinitely. To remove it you can use a free tool cal…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    846 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

    Need Help in Real-Time?

    Connect with top rated Experts

    9 Experts available now in Live!

    Get 1:1 Help Now