Results 1 to 7 of 7
  1. #1
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default Access textbox value in javabean

    I have an application, in which I want to accept value from the user, in textbox and want to send this value as a parameter to the query in javabean.

    here is the application--

    Index.jsp
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">

    <%@ page language="java" import="java.sql.*" %>
    <jsp:useBean id="mybean" scope="page" class="newpackage.NewClass" />
    <jsp:setProperty name="mybean" property="*" />





    <html>
    <head>
    <title>Book Entry FormDocument</title>


    </head>
    <body><center>
    <form action="BookEntryForm.jsp" method="post" name="entry" >
    <input type="hidden" value="list" name="action">
    <table border="1" cellpadding="0" cellspacing="0">
    <tr>
    <td>
    <table>
    <tr><td colspan="2" align="center"><h2>Book Entry Form</h2></td></tr>
    <tr><td colspan="2">&nbsp;</td></tr>
    <tr><td>Book Name:</td><td><input name="bookname" type="text" size="50"></td></tr>
    <tr><td>Author:</td><td><input name="author" type="text" size="50"></td></tr>


    <tr><td colspan="2" align="center"><input type="submit" value="Submit"></td></tr>
    </table>
    </td>
    </tr>
    </table>
    </form>
    </center>

    </body>
    </html>

    response.jsp

    which will display the value of the textbox

    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
    <jsp:useBean id="mybean" scope="page" class="newpackage.NewClass" />
    <jsp:setProperty name="mybean" property="*" />
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>JSP Page</title>
    </head>
    <body>
    <h1>Hello World!</h1>

    <% out.print("The new name is"+ mybean.name()); %>
    <p><font size="6">Welcome :&nbsp; <%=request.getParameter("bookname")%></font></p>

    </body>
    </html>
    NewClass.java


    here is the class in which I need the value of the textbox.
    package newpackage;

    public class NewClass {
    private String bookname;

    public NewClass() {
    bookname = null;
    }

    public void setUsername( String name ) {
    bookname = name;
    }

    public String getUsername() {

    return bookname;
    }

    public String name()
    {

    String str= getUsername() ;
    System.out.println("Surname"+ str);

    return str;

    }


    }


    here the str produce null value

    Please help

  2. #2
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    195
    Rep Power
    5

    Default

    I've never mixed javascript and java, I do not know if that is possible? If it were, I would suspect you could call bookname.getValue() type of thing. I am use to using jsp with js and java with java.

    I'm curious of this answer to your question as well.
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  3. #3
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default

    Hi,
    My main concern is that I am trying to accept some value in a textbox, and do some further calculation, based upon the textbox value.

    But there are lot of operation to do, so I am writing a java class for that and in the query, I want to pass the value of the textbox as argument.

    Can you suggest me what is the best way to do that?

    Thank you

  4. #4
    dswastik is offline Senior Member
    Join Date
    Dec 2008
    Location
    Kolkata
    Posts
    282
    Rep Power
    6

    Default

    What is usebean doing in index.jsp? It should be in BookEntryForm.jsp because index.jsp is submitting data to this page, and in response.jsp use getproperty, request.getParameter won't help because submitted request is not coming to this page. Probably you are also missing the property for author in your bean class.
    Swastik

  5. #5
    Sno's Avatar
    Sno
    Sno is offline Senior Member
    Join Date
    Apr 2010
    Posts
    195
    Rep Power
    5

    Default

    How to get dropdown value using jsp:useBean and jsp:setProperty? - Stack Overflow
    or
    http://www.java2s.com/Tutorial/Java/...etProperty.htm

    read this. This should answer your question
    should be similar to this... i hope, this is for dropdown. not textbox.
    Selected bookname: ${NewClass.bookname}
    Last edited by Sno; 05-13-2010 at 04:29 PM. Reason: Adding url
    :rolleyes: ~ Sno ~ :rolleyes:
    '-~ B.S. Computer Science ~-'

  6. #6
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

    Default

    I have remove the usebean from the index.jsp.

    By using the request.getParameter("bookname")
    I can access the value of bookname,in bookentry.jsp.

    But I didnt get the value in the bean class.

  7. #7
    newto is offline Member
    Join Date
    May 2010
    Posts
    17
    Rep Power
    0

Similar Threads

  1. Clock JavaBean
    By dns.gonz in forum AWT / Swing
    Replies: 9
    Last Post: 10-08-2010, 05:49 AM
  2. JavaBean
    By hannes in forum New To Java
    Replies: 5
    Last Post: 02-14-2010, 08:51 PM
  3. components in javabean
    By NAIYYAR ALI in forum Advanced Java
    Replies: 0
    Last Post: 10-05-2009, 04:36 PM
  4. Enterprise JavaBean 3.0
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 06-20-2008, 12:42 AM
  5. JavaBean Problem
    By Peter in forum Advanced Java
    Replies: 2
    Last Post: 07-05-2007, 02:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •