Using java bean with jsp

hello friends,
i'm new to jsp. i want to create an html form that accepts username and a value from four radio buttons and display back the entered name and checked radio button's value using java bean.
i use the <jsp:setProperty id="" property="*"> method. i don't know how to access the radio buttons value from the html.
also when i use an additional field other than username the jsp page is showing error.
Please give me the correct method to use java bean with jsp in this circumstance.
thank you.

thank you, but i have a problem left. the case is like this.
i got the jsp and bean worked fine when i have a sinle input text field.
but when i added a second text field i recieved the following error.
javax.servlet.ServletException: basket.newbean.getUserPass()Ljava/lang/String;
     org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:825)
     org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:758)
     org.apache.jsp.newform.process_jsp._jspService(process_jsp.java:69)
     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)
where userPass is the new form element. I have made the subsequent chanes in my bean program and jsp file.
pls hlp.

Similar Messages

  • Problem in using java bean with jsp

    Hi,
    This is my code and i get this error. Not able to trace the mistake.
    bean.html
    <html>
    <head>
    <meta http-equiv="Content-Language" content="en-us">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>Fname</title>
    </head>
    <body>
    <form method="POST" action="http://localhost:8080/beanjsp.jsp">
         <p>Fname: <input type="text" name="T1" size="20"></p>
         <p>Lname: <input type="text" name="T2" size="20"></p>
         <p> </p>
         <p> </p>
         <p><input type="submit" value="Submit" name="B1"><input type="reset" value="Reset" name="B2"></p>
    </form>
    </body>
    </html>
    beanjsp.jsp
    <jsp:useBean id="bean" class="beans.FirstBean" scope="application" />
    <jsp:setProperty name="bean" property="fname" param="T1" />
    <jsp:setProperty name="bean" property="lname" param="T2" />
    THE FIRST NAME IS <%=bean.getFname() %>
    THE LAST NAME IS <%=bean.getLname() %>
    FirstBean.java
    //CREATING A BEAN
    package beans;
    import java.io.*;
    public class FirstBean
         private String fname;
         private String lname;
         FirstBean()
              fname="";
              lname="";
         public void setFname(String fn)
              fname=fn;
         public void setLname(String ln)
              lname=ln;
         public String getFname()
              return fname;
    public String getLname()
              return lname;
    error report
    org.apache.jasper.JasperException: /beanjsp.jsp(2,0) The value for the useBean class attribute beans.FirstBean is invalid.
         org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
         org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:405)
         org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:146)
         org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1223)
         org.apache.jasper.compiler.Node$UseBean.accept(Node.java:1116)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
         org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
         org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
         org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
         org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
         org.apache.jasper.compiler.Generator.generate(Generator.java:3270)
         org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
         org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
         org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
         org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
         org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
         org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
         javax.servlet.http.HttpServlet.service(HttpServlet.java:802)I have placed the beans package folder containing FirstBean.class inside classes folder of ROOT directory.
    I don't know what s wrong with my code :( ... Plz help asap.
    Thanks,
    Akshatha

    I have placed the beans package folder containing FirstBean.class >inside classes folder of ROOT directory.Place it in the WEB-INF/classes folder
    ram.

  • Using java beans in jsp using tomcat

    hi i have made a form to enter user first name and last anme with html and then i have made a value javabean in which i want to store the information filled bu user. i want to display the information stored in java bean in jsp page i have made the full application and i have made class file of java bean as well as jsp file but when i try to run this web application in tomcat i am getting class not found exception.
    could anybody tell me that where i should store the bean class in tomcat and do i need to make any package in which i have to place my java bean file plz tell me complete procedure along with code if possible

    whew thats a lot of questions... All of this is pretty basic stuff. I would recommend you take a look at the web services tutorial: http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
    lets see.
    Starting a package name with com is just a generic standard which is followed.
    It is most correct when creating commercial packages to create packages like com.companyName.project
    http://java.sun.com/docs/codeconv/html/CodeConventions.doc8.html
    You should not need a page import directive unless you are using classes in scriptlets: ie <% %> tags in your JSP. Your jsp:useBean tag will automatically import necessary classes - you don't need to import classes for beans specifically
    <jsp:useBean id="myClass" scope="session" class="com.myPackage" />
    Your directory structure should be something like this
    webApplicationRootDirectory
    - page1.html
    - page2.html
    - page3.jsp
    - page4.jsp
    - WEB-INF
         - web.xml
         - classes
           - com
             - myPackage
               - myClass.classerrrm. Thats about it I think.

  • Using Java Bean in JSP to show database record

    I have links in my Tomcat container that if someone clicks on a specific link it should go to a Record page (Show.jsp) with all the values associated with a record from a database.
    For example if someone clicks on a specific link like this:
    LinkExample
    it would take you to a jsp with database info for someone named Jones and show you his info:
    Lastname = Jones
    Firstname = Mike
    City = San Diego
    I would like to do this using a Java helper class and bean so I dont have any database connection or Java code in my JSP.
    I created Java class file that has Database connection that works with a Java bean. I just dont know how to get the Show.jsp to work with the Java Bean and Java helper class file.
    Here is what I have for Show.jsp and this is the part I have been working on the longest but cant get it to work because it doesnt seem to work with the database:<jsp:useBean id="user" class="num.UserDB"/>
    //do I call getUser(lastname) here and if so how?
    <jsp:setProperty name="user" property="*"/>
    Last Name: <jsp:getProperty name="user" property="lastname"/><BR>
    First Name: <jsp:getProperty name="user" property="firstname"/><BR>
    City: <jsp:getProperty name="user" property="city"/><BR>My Java Helper class that compiles and connects to database:
    package num;
    import java.io.*;
    import java.sql.*;
    import java.util.*;
    import num.User;
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName...//database connection stuff here
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
            user.setFirstname(results.getString("city"));
         catch(Exception e)          
                   System.out.println("Exception...");               
       return user;
    }My Java Bean that compiles here:
    package num;
    public class User
      private String firstname;
      private String lastname;
    private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, String city)
           this.lastname = lastname;
              this.firstname = firstname;
              this.city = city;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      //more bean methods for all fields here
     

    Sorry if I wasnt specific enough. I have a link that passes a value (field that is passed is called lastname) to a JSP where I want to show record info for that value that is passed.
    My question is how do I show the database record info on Show.jsp for the lastname field value of Jones where I want to use a Java Bean and Database helper class in Show.jsp
    Here is the message I get when I hit the link (LinkExample) and it goes to Show.jsp:
    org.apache.jasper.JasperException: Cannot find any information on property 'lastname' in a bean of type 'num.UserDB'
    .....My UserDB class:
    public class UserDB
    public User getUser(String lastname)
    User user = new User();     
            try          
         Class.forName("org.gjt.mm.mysql.Driver");
        Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/dbconnone?user=smitherson&password=abcdefg");
        Statement stmt = conn.createStatement();
        ResultSet results = stmt.executeQuery("SELECT * from user where lastname = '" + lastname + "'");
         if(results.next() == true)
         results.next();
         user.setLastname(results.getString("lastname"));
         user.setFirstname(results.getString("firstname"));
                         user.city(results.getString("city"));
         catch(Exception e)          
             System.out.println("Exception..." + e);          
       return user;
    }Bean class:
    package num;
    public class User
      private String firstname;
      private String lastname;
      private String city;
      public User()
         //no arg constructor
      public User(String firstname, String lastname, Sting city)
          this.firstname = firstname;
           this.lastname = lastname;
    this.city = city;
      public String getFirstname()
              return firstname;
      public void setFirstname(String firstname)
         this.firstname = firstname;
      public String getLastname()
              return lastname;
      public void setLastname(String lastname)
         this.lastname = lastname;
      public String getCity()
              return city;
      public void setCity(String city)
         this.city = city;
      

  • Problem in Using Java Bean in JSP

    Hi,
    I have a bean called BankAccount.....I tried to use it in a jsp file called Usebean.jsp like this <jsp:useBean id="BA" class="BankAccount" scope="application" /> I tried in both tomcat and j2ee1.3 server... but when i run the jsp file i get an error saying..... Class.org.apache.jsp.BankAccount not found...... But i have put the class file properly inse classes folder.....
    Can anyone help me soon..... i am new to JSP........
    Thanks,
    Akshatha

    Well u need to have your class in a package
    like mypackage.BankAccount
    and put your class in classes/mypackage
    <jsp:useBean id="BA" class="mypackage.BankAccount" scope="application" />

  • How can i use JAVA BEAN and JSP?

    well, i have developed all my web apps by using pure JSP only, i know this sucks, but i dont know how to start on using beans... what directory should i put them into... etc... what are the good programminmg practices/standards/techniques when incorporating beans in jsp???

    Standards are pretty loose, but generally, Beans hold a lot of the backend logic for your JSP. This can include data validation before entering into the database, database inserts, queries, data manipulation. The JSP should really only contain code that will retrieve the data from the bean and appropriately output it.
    As far as using them, you can use the <jsp:useBean> tag in your JSP. As long as the bean is stored somewhere that your classpath points to, you're all set. From then on, you can use it like any other object in your JSP.

  • Using java files with JSP

    Ok, so im pretty new to this JSP lark and have a question.
    I have Java Classes resting in .java files, i need to know how
    do i link these files to my .jsp page so that the classes/variable etc.
    declared with the java files are recognised when they are come
    across in the .jsp file.
    I dont know if I have explained that properly.

    Just include this statement at the top of your jsp:
    <%@page import="yourpackage.yourclass"%>
    The .java files should of course be compiled into .class files prior to using (and you don't include the extension when importing).

  • Using java beans in jsp

    Hi, I need to do this, can any one help me.
    In the signup form, i have some text frields like this
    HTML
    <form action=http://localhost:8080/servlet/Signup.jsp">
    <input type=text name=name>
    <input type=text name=phone>
    <input type=submit value="Submit">
    </form>
    JAVASP
    req.getParameter("name");
    req.getParameter("phone");
    i am doing some validation here like if the user name exists in the database i am diverting him to the html page like this
    rs = st.executeUpdate("select * from regi where user="+name+"");
    if(rs.next())
    here i need to call the html page in the from of a bean and with the old values intact to it
    else
    insert into regi values('"+name+"','"+phone+"')
    this is how i am doin my html in the form of a bean
    <%!
    public void beans()
    %>
    <form action=http://localhost:8080/servlet/Signup.jsp">
    <input type=text name=name value=<%=name%>>
    <input type=text name=phone value=<%=phone%>>
    <input type=submit value="Submit">
    </form>
    <%!
    %>
    but this is giving me error, can any one help me please?
    Thanks
    Uma

    Hai Uma,
    I read ur code like this.
    <%!
    public void beans()
    %>
    <form action=http://localhost:8080/servlet/Signup.jsp">
    I think here is the mistake. <%! %> - for declaring variables. But for writting codes we have to use <% %> tags only. Can u try the same program by removing "{" in this tags or remove "!" from tag...
    I hope this may helpful to u to solve ur problem
    With Regards
    Siva

  • What's the difference between using java directly in JSP and java bean

    What is the difference if I use java code directly in JSP or use java bean in JSP?
    Which class to use for receiving the passed parameter from html or java script? Any difference for java code and java bean in the way receiving the passed data?
    How can I pass string from jsp to html or java script?

    1 Cleaner pages
    2 you have to write the class and use set and get methods
    3 What do you mean when saying passing string from jsp to html??, do you mean the value you can use <%=variablename%>

  • What is the difference between java direct or java bean in JSP?

    What is the difference if I use java code directly in JSP or use java bean in JSP?
    Which class to use for receiving the passed parameter from html or java script? Any difference for java code and java bean in the way receiving the passed data?
    How can I pass string from jsp to html or java script?

    it's generally accepted as better design to separate presentation from logic. meaning, the java code in the jsp should be used to support displaying data, as oppsoed to implementing the application - like database access, etc.
    when the logic is separated from the presentation, it allows you to reuse logic components within several jsp pages.
    if you decide to change the presentation layer in the future (to support wap, for example) you don't need to rewrite your entire application, since the "guts" of the application is outside of the jsps.
    it is also a good idea to separate your business logic from your data layer. adding a "buffer zone" between these layers helps in the same manner as in separating presentation from logic. if you're using flat files for storage now, upgrading to a database wouldn't require rewriting all your business logic, just the methods which write out the data to a file, for example.
    once you feel comfortable with separating the various layers, check out the struts framework at http://jakarta.apache.org/
    to answer your second question, to get parameters passed in from HTML forms, use ServletRequet's getParameter() method.
    in tomcat:
    <% String lastName = request.getParameter( "lastname" ); %>
    to answer your third question: when displaying the HTML from withing a jsp, print out the string to a javascript variable or a hidden form element:
    <% String firstName = "mike"; %>
    <input type="hidden" name="firstname" value="<%= firstName %>">
    <script language="javascript1.2">
    var firstName = "<%= firstName %>";
    </script>
    this jsp results in the following html:
    <input type="hidden" name="firstname" value="mike">
    <script language="javascript1.2">
    var firstName = "mike";
    </script>

  • Navigation Panel using Java Bean Base API

    Hi,
    I would like to know how do I add the standar navigation panel to my map using the oracle.lbs.mapclient.MapViewer object. I have try different forms which include adding a tile theme layer but its not working. I'm not using the JS API since I want to have an applet.
    Thanks in advance.
    Susana

    Hi,
    in MapViewer's web page there is a link to some demos. There you can find a few examples of how to use the Java bean with jsp pages.
    If you want to implement a simple java (desktop) application, the following code contains the basic information that you need to start the MapViewer object, set the display parameters, and then add some information to generate a map image. In this example, a base map is used to generate the map.
        String url = "http://localhost:7001/mapviewer/omserver";
        try
          MapViewer mapViewer = new MapViewer(url);     // creates MapViewer object
          mapViewer.setDataSourceName("mvdemo");       // sets the data source (must exist in Mapviewer server)
          mapViewer.setMapTitle("MVDEMO base map");           
          mapViewer.setAntiAliasing(true);    
          mapViewer.setImageFormat(MapViewer.FORMAT_RAW_COMPRESSED);
          mapViewer.setDeviceSize(new Dimension(600,475));
          mapViewer.setCenterAndSize(-116.65,38.92,19.2);         // sets the map area
          mapViewer.setBaseMapName("DEMO_MAP");
          System.out.println(mapViewer.getMapRequestString());    // this prints the current map request to be issued
          boolean response = mapViewer.run();      // executes the request
          if (response)
              Image img = mapViewer.getGeneratedMapImage();
             // do something with the image in your Java application
        }catch(Exception ex)
           ex.printStackTrace(System.err);
        }The API java doc (see APIs link in MapViewer's web page) contains a more detailed description of the methods that can be used with the Java bean API.

  • Can we use an overloaded constructor of a Java Bean with Session Tracking

    Hi Friends,
    If any one can solve my query.... It would be helpful.
    Query:
    I have a Java Bean with an overloaded constructor in it. I want to use the overloaded constructor in my JSP.
    1. One way of doing that is to use it directly in the "Scriptlets" (<% %>). But then I am not sure of the way to do session tracking. I think I can use the implicit objects like "session", "request" etc. but not sure of the approach or of the implementation method.
    2. Another way is through the directive <jsp: useBean>. But I cannot call an overloaded constructor with <jsp: useBean>. The only alternative way is to use the directive <jsp: useBean> where I have to write getter and setter methods in the Java Bean and use the <jsp: setProperty> and <jsp: getProperty> standard actions. Then with this approach I cannot use the overloaded constructor.
    Can any one suggest me the best approach to solve this problem ?
    Thanks and Regards,
    Gaive.

    My first reaction is that you can refactor your overloaded constructor into an init(arguments...) method. Instead of overloaded constructor, you can call that init method. This is the ideal solution if possible.
    As to the two choices you listed:
    1. This is OK, I believe. You can use scriplet to define the bean and put it into session scope of the pageContext. I am not sure exactly what you meant by session tracking; whatever you meant, it should be doable using HttpSessionAttributeListener and/or HttpSessionBindingListener.
    2. Agreed. There is no way that <jsp:useBean> can call a constructor that has non-empty arguments.
    Please tell me how it works for you.

  • Stepping into Java Beans from JSP

    I am trying to figure out how to step into the Java Source code for my beans that are used in my JSP pages. I need to be able to debug them by stepping into them, using break points, etc.
    I have Nitro installed and a sample JSP page with the import to my test Java Bean class. What I did was create two projects in my work space. One as a Web project application and one as a Java project. I referenced and opened both projects. Everything compiles fine and the syntax is correct.
    The problem is I can not make the link for importing the class.
    I get this error: Class com.BrianTest.MyBean not found in import com.BrianTest.MyBean
    Anyone got a clue or a good example? I did try and add the class path and I tried to put it in a Jar file and attach the source to the Jar, but same problem.
    Thanks :?

    Stepping into jsp:useBean is not possible, but you can step-into jsp getter & setter tag.
    Since you are using java bean from a dependent project you need to configure your server with DevLoader.
    And currently only Tomcat server can be configured with Sysdeo Devloader to handle this situation
    Download Sysdeo DevLoader for Tomcat from http://www.sysdeo.com/eclipse/tomcatPlugin.html
    NOTE: If the project is self sufficient and not dependent on other projects/locations for classess/libraries then NitroX picks up all the libraries & classes present within default WEB-INF/lib & WEB-INF/classes respectively. And in this case you need not modify server configuration.
    Sysdeo DevLoader is to allow your web project to use libraries/classes from dependent projects. All you need to do is extract DevLoader.zip present within tomcatPluginV3.zip inside your Tomcat/server/classes folder.
    For more information about DevLoader please refer to http://www.sysdeo.com/eclipse/readmeDevLoader.html
    This will solve your problem and you should be able to run/debug your application. And most important make sure you have the correct NitroX build that supports Sysdeo DevLoader, refer http://www.m7.com/whatsnew.htm document against your build id (Help > About NitroX > NitroX Icon)

  • How to use Java Beans In JSTL?

    Hi
    I want to know how to use Java bean in JSTL
    please explain this with giving any one example.
    Thanks-
    Swapneel

    A bean is obtain by <jsp:useBean> tag nd once bean is obtained we can get its property by using getProperty tag.

  • Using java beans to store records from recordset

    Hi there,
    I have been stuck on an issue with Java Beans in JSP for the last few days and cant get my head around it.
    I am basically trying to retrieve all the records out of a resultset which pulls records from a table through a JDBC connection and store the records in a html table using the java beans getProperty tag.
    Problem is that the first row of the recordset is being applied to every row in the table. I have tried implementing for loops to iterate through the result set but without any luck.
    I need help urgently
    Thank you

    Thanks for the feedback M
    I have added the JSTL 1.1 library and used the Foreach components and data source components which now totally eliminate the need for beans altogether. :P
    <c:forEach var="row" items="${deejays.rows}">
    <tr onmouseover="this.bgColor='gold';"
    onmouseout="this.bgColor='#FFFFFF';">
    <c:forEach var="column" items="${row}">
    <td>
    <c:out value="${column.value}"/>
    </td>
    </c:forEach>
    <td width="24%" align="center">
    <input type="image" src="7af5.jpg" name="test" value="test"/>
    </td>
    <td width="15%">
    <input type="radio" name="book1"/>
    </td>
    </tr>
    </c:forEach>
    </table><p align="left">
    How and where do i add the beans in here now???

Maybe you are looking for

  • Issue in dequeuing messages on Linux using AQjmsTextMessage_C.getFactory().

    Hi All, This is regarding issue related to Dequeuing of message from AQ on Linux platform using JAVA API. Our appliaction is sending message on AQ which has queue payload type of type 'SYS.AQ$_JMS_TEXT_MESSAGE'. For dequeuing of this message we are u

  • Group changes when file is created in the GUI

    Hello All, Here is a outline of my situation. On a 10.5 or 10.6 client machine if I go to System Prefs, Accounts and click on the "+" and change to "group" and add a new group called "video" and set the GID to 264, it will create the new group. Then

  • Got what it takes to get me going?

    Hi... As a newbie I need some help. I've been fighting with Borland Foundation 2005 to compile 2 samples from sun namely SerialDemo and JavaSoundDemo. I appear to get a blast of errors from the compiler. I can run the bytecode that is supplied and th

  • Obtaining equations with 3D graph

    This is what I'm trying to do but I'm not too certain whether it's doable in Labivew or not. Basically I have a program which collects bunch data points and insert them into arrays. The 3 sets of arrays I have are: Water Weight Water Ratio Reflectivi

  • ICWC case from 4.0 to 5.0, how to find an existing case

    I don't see how to find an existing case in CRM 5.0.  I'm trying to link a service ticket to an existing case I know 5.0 required some additional configuration to assign Case profile in CRMC_IC_MAIN and I created the case profile in config ICWC > bus