Help needed: clarifying the use of beans to pass data from database to JSP

Hi everyone,
I am sure you all get fed up with being asked this question as I can see it is asked a lot when googled, but the answers given have not cleared things up for me.
Anyway, I have a JSP page that contains a text box, submit button and a select box of size 10. The user enters a search string and the form submits the data and reloads the same page. From the code you can see the Name property of the bean is set.
<jsp:useBean id="vtm" class="FinalYearProject.Types.VtmType" scope="page" />
<jsp:setProperty name="vtm" property="NM" value="${param.NM}" />I then need to be able to use that name to query a postgresql database. I have a JDBCConnector class with the method:
    public ResultSet searchTable(String NM ) throws SQLException {
        String[] names = NM.split(" ");
        NM = "";
        for(int i = 0; i < names.length; i++) {
            NM = names[i] + "%";
        return stat.executeQuery("SELECT * FROM vtm WHERE nm ILIKE '" + NM + "';");
    }This method however can be changed.
My question really is what is the best way for me to take the name, get the resultset and pass back the VtmType objects to the jsp so that I can populate my select box, and where should each part be handled i.e. the JSP page, the VtmType, the JDBCConnector.
I may be going about it completely the wrong way and using beans incorrectly, but I just cant seem to get my head around the problem.
Any help would be much appreciated,
Thanks.

Hi,
Thanks for the help, I actually found some literature about the JSP Model 2 and realised that was what I needed to do. I have now re-written everything and it has made my life a lot eaiser, typically this was before I checked back on this post though!
Anyway, I now have JSP pages requesting Servlets which create beans and call classes that access the database. The servlet then forwards the beans and where necessary a small of html to another JSP. Like you have suggested.
One problem I have now however, is that the user needs to be logged in to access some of the pages. An error page with the correct message is displayed to the user when it is processed via the servlet.
//Servlet detects an error
request.setAttribute("errorMsg", "1");
gotoPage("/loginError.jsp", request, response);
//JSP detects which errorMsg to display
<c:set var="errorMsg" value="${requestScope.errorMsg}" />However, when the user does not sign in and clicks a link which is blocked the JSP forwards directly to the error JSP.
//Tests to see if user is logged in
<c:if test="${empty user.username}">
    <jsp:forward page="/loginError.jsp">
        <jsp:param name="errorMsg" value="3" />
    </jsp:forward>
</c:if>The problem with this is that the only way I can see of checking the errorMsg type is with:
//JSP checks which errorMsg to display
<c:set var="errorMsg" value="${param.errorMsg}" />Which is different to how I determine the errorMsg from the Servlet. Is there a way of getting the errorMsg type that is the same for both actions?
Thanks.

Similar Messages

  • Pass data from servlet to jsp using sendRedirect

    Hi,
    I am passing data from servlet to jsp using forward method of request dispatcher but as it doesn't change the url it is creating problems. When ever user refreshes the screen(browser refresh) it's re-loading both servlet and jsp, which i don't want to happen. I want only the jsp to be reloaded.
    Can I pass data from servlet to jsp using sendRedirect in this case. I also want to pass some values from servlet to jsp but without using query string. I want to set some attributes and send to jsp just like we do for forward method of request dispatcher.
    Is there any way i can send data using attributes(without using query string) using sendRedirect? Please let me know

    sendRedirect is meant as a true redirect. meaning
    you can use it to redirect to urls not in your
    context....with forward you couldn't pass information
    to jsps/servlets outside your own context.Actually, you can:
    getServletContext().getContext("/other").getRequestDispatcher("/path/to/servlet").forward(request, response)I think the issue here is that the OP would like to have RequestDispatcher.forward() also update the address in the client's browser. That's not possible, AFAIK. By the time the request is forwarded, the browser has already determined the URL of the servlet, and the only I know of way to have the browser change the URL to the forwarded Servlet/JSP is to send a Location: header (i.e. sendRedirect()). Remember that server-side dispatching is transparent to the client. Maybe there's some tricky stuff you can do with JavaScript to change the address in the address bar without reloading the page?
    Brian

  • Help Required -- Can we use SQL Query to READ data from SAP MDM Tables

    Hi All,
    Please help.........
    Can we use SQL Query to READ(No Creation/Updation/Deletion  just Read) Data from SAP MDM tables directly, without using MDM Syndicator.
    Or direct SQL access to SAP MDM tables is not possible. Only through MDM Syndicator can we export data.
    Thanks in Advance
    Regards

    All the tables you create in Repository comes under A2i_CM_Tables in Database named as your repository name. So the tables names are fields of table A2i_CM_Tables. Now i tried it but cant make it.
    Now, I dont think its possible to extract all fields in tables and there values using select query. May be pure sql guy can do that or not.
    But there is no relation of data extraction and syndicator. Data is viewed in Data Manager. and you can also store data in a file from DM also.
    BR,
    Alok

  • Using a paramter to fetch data from database

    Hello SAP,
    Is there a way to use a parameter that takes in the employee ID and have it fetch from the database the employee name.  Just to note, the tables that I am using in this report do not link to the employee table that contains the employee name. I just want to be able to use a parameter that can fetch me the name from the database dynamically so that it prints in the report header. 
    Is this possible?
    Thanks in advance,
    Z

    Thanks for your responses all.
    I tried what you've recommended. I tried but it didn't seem to work.  Perhaps I misunderstood so please let me know if I did.  I'll elaborate a bit more of what I'm looking to achieve.
    I have a report that gives information that pertains to an employee.  The three tables in the report have no reference to the employee table (meaning I cannot link the Emp ID field to any field of the three tables).  We as the firm know based on coding within the three tables which employee the records within the report beloing to.
    So basically, I want to be able to display the employee's full name in the Report Header by using a parameter.  I want to enter the employee ID in the parameter field and have it display the employee name in the report header.
    I tried to insert the Employee table in my report as the only "unlinked" table in my report.  I tried to create a formula as:
    @Employee Name
    if {?Emp ID} = {Employee table. Emp ID} then
    {Employee Name}
    This resulted in as a null value when I inserted it into the report header.
    I also tried creating a formula as such:
    @Employee Name (2nd)
    BeforeReadingRecords;
    Global StringVar FullName;
    if {?Emp ID} = {Employee table. Emp ID} then
    FullName:={Employee Name};
    This did not work either as the error message stated the field {Employee table.Emp ID} must be evaluated later.
    If I'm heading in the wrong direction can someone steer me back into the right direction? 
    Sastry, if I need to use the Add Command feature to fetch the data, is there a way to dynamically insert the parameter value in the SQL so that only the record that you want to be brought back into your report comes back?
    Thanks again to all!
    Z
    Edited by: Zack H on Jan 19, 2009 8:34 PM

  • Passing Data From One Component To The Node Of An Other Component

    Hi Experts,
        I have a component A (parent) in which i am usuing an other component B (child) . From the parent component i am able to pass data to the child component by using one of the child's interface node but when i try to use one of the parents interface nodes to pass data from the child to the parent component i am unable to pass data as required .
        Please tell me where i am going wrong.
    Thanks In Advance,
    Chaitanya.

    In Component B, check the property of the Interface node Input Element( Ext.) tick it.
    Now, bind the node like the one we do in ALV
    Abhi

  • Can you help me understand the use of the word POSITION in TR and CFM?

    Hi,
    I am trying to have a view of typical BI reports in TR and TM/CFM so through my research I came to the following link:.
    http://help.sap.com/saphelp_nw2004s/helpdata/en/62/08193c38f98e1ce10000000a11405a/frameset.htm
    My problem on this link and other postings on this site seem to be the same. Can you help me understand the use of the word POSITIONS in these context:
    1. Our client has asked for financial transaction reports in BW, such as position of Borrowings, Investments and Hedge Operations (TM data).
    2. I have a requirement on, some reports related to Money Market (Fixed Term Deposits, Deposits at Notice) something on FSCM-Treasury and Risk Manager. These reports will be similar to that of Loans, i.e. Position statement, flow statement, etc.
    3. The set of position values for a single position or a limited amount of positions can be reported by transactions TPM12 and TPM13 in R3.
    4. 0CFM_C10 (Financial Positions Cube)
    Do you have some simple report outputs to help clarify how the word POSITION is used in such environments?
    Thanks
    Edited by: AmandaBaah on Feb 15, 2010 4:39 PM

    If I future buy 10 shares in company at £1 per share - at the end of the day my potential value is £10
    The next day the shares drop tp £0.9 per share - I have a negative position - my shares are only worth £9
    I haven;t bought them yet - but I have a negative position - ie if things stayed as they are - I am going to realise (ie end up with)  a loss
    Now you can use this for loans and foreign exchange banks as well...

  • What is the use of bean?

    I'm new to JSP.What is the use of bean? And how do we write it? Can I do the JSP which connect to database without using the bean?

    You don't need JavaBeans when working with JSPs. For info on JavaBeans look here: http://developer.java.sun.com/developer/onlineTraining/Beans/beans02/
    As a general rule of thumb it's not a very good idea to have JSPs connect directly to a database. I'd higly recommend you pickup "Java Servlet Programming" from O'Reilly, it covers Servlets, JSPs and how to tie them together.

  • I need to pass data from an Access database to Teststand by using the built in Data step types(open data

    base /open SQL Statement etc) the first time i defined the system everything was fine but when i changed the Database (using M.S.Access) the " open SQL Statement" it would show the tables but not thier columns ,I"m using win98 sec edition / Teststand 1.0.1i need to pass data from an Access database to Teststand by using the built in Data step types(open database /open SQL Statement etc) the first time i defined the system everything was fine but when i changed the Database (using M.S.Access) the " open SQL Statement" it would show the tables but not thier columns ,I"m using win98 sec edition / Teststand 1.0.1
    When I tried the same thing on another cmputer the same thing
    happend
    appreiciate u"r help

    base /open SQL Statement etc) the first time i defined the system everything was fine but when i changed the Database (using M.S.Access) the " open SQL Statement" it would show the tables but not thier columns ,I"m using win98 sec edition / Teststand 1.0.1Hello Kitty -
    Certainly it is unusual that you can still see the tables available in your MS Access database but cannot see the columns? I am assuming you are configuring an Open Statement step and are trying to use the ring-control to select columns from your table?
    Can you tell me more about the changes you made to your file when you 'changed' it with MS Access? What version of Access are you using? What happens if you try and manually type in an 'Open Statement Dialog's SQL string such as...
    "SELECT UUT_RESULT.TEST_SOCKET_INDEX, UUT_RESULT.UUT_STATUS, UUT_RESULT.START_DATE_TIME FROM UUT_RESULT"
    Is it able to find the columns even if it can't display them? I am worried that maybe you are using a version of MS Access that is too new for the version of TestSt
    and you are running. Has anything else changed aside from the file you are editing?
    Regards,
    -Elaine R.
    National Instruments
    http://www.ni.com/ask

  • Please help needed os x lion I wish to transfer photos from the iPhoto library to a album or folder then delete them from the Library but when I do this it also deletes them from the album ? how do I do this please.

    Please help needed os x lion I wish to transfer photos from the iPhoto library to a album or folder then delete them from the Library but when I do this it also deletes them from the album ? how do I do this please.

    Albums are not places to store photos, they're more like "labels" you can apply to photos to better organize them. A single image file can be in multiple albums... they are not copies, it's simply been labelled as being in all those albums. So what you're trying to do doesn't make sense, because it's based on incorrect assumptions.
    The iPhoto library will always show all photos that you have added to iPhoto.

  • What are the uses of diffrent concepts in data warehousing

    What are the uses of diffrent concepts in data warehousing? Why?
    naveen

    Hi,
    Your statement is correct. To be crisp, the portal offers a single point of access to SAP and non-SAP information sources, enterprise applications, information repositories, databases and services in and outside your organization—all integrated into a single user experience. It provides you the tools to manage this knowledge, to analyze and interrelate it, and to share and collaborate on the basis of it.
    With its role-based content, and personalization features, the portal enables users—from employees and customers to partners and suppliers—to focus exclusively on data relevant to daily decision-making processes
    To read more visit,
    http://help.sap.com/saphelp_nw04/helpdata/en/a9/76bd3b57743b09e10000000a11402f/frameset.htm
    Regards
    Srinivasan T

  • Help , How to get data from database using recordset with UI API

    I want to get a data from database
    when I want to create recordset i notice that UI API didn't has record set
    so I created recordset using DI API (SAPbobscom.recordset and SAPbobscom.company)
    ======================================================
    Dim oCompanyUI As SAPbouiCOM.Company <<UI API
    Dim oRecSet As New SAPbobsCOM.Recordset << DI API
    Dim oCompanyDI As New SAPbobsCOM.Company << DI API
    '=====================================================
    oCompanyDI.Connect
    Set oRecSet = oCompanyDI.GetBusinessObject(BoRecordset)
    oRecSet.DoQuery ("SELECT T0.CardCode, T0.CardName FROM OCRD T0")
    SBO_Application.MessageBox oRecSet.Fields.Item(1).Value
    ======================================================
    but I got an error it said "you are not connected to company"
    I'm really don't have an idea about how to get a data from using UI API (exp I want to get a date or costumer code)
    can someone help me please, I really need it
    Thanks

    you need a single sign on
            Dim oDICompany As SAPbobsCOM.Company
            Dim sCookie As String
            Dim sConnStr As String
            Dim ret As Integer
            oDICompany = New SAPbobsCOM.Company
            sCookie = oDICompany.GetContextCookie
            sConnStr = SBO_Application.Company.GetConnectionContext(sCookie)
            If oDICompany.Connected Then
                oDICompany.Disconnect()
            End If
            ret = oDICompany.SetSboLoginContext(sConnStr)
            If Not ret = 0 Then
                SBO_Application.MessageBox("set Login Context failed!")
                Exit Sub
            End If
            ret = oDICompany.Connect()
            If Not ret = 0 Then
                SBO_Application.MessageBox("Company Connect failed!")
            End If

  • I want to delete my data from iphone while i doesnot have the access but i know my apple id so plz help me its urgent, i want to delete my data from iphone while i doesnot have the access but i know my apple id so plz help me its urgent

    i want to delete my data from iphone while i doesnot have the access but i know my apple id so plz help me its urgent, i want to delete my data from iphone while i doesnot have the access but i know my apple id so plz help me its urgent

    Welcome to the Apple Community.
    You can only wipe your device when it is logged into iCloud and 'Find My Phone' is enabled, additionally the device will need to be switched on and connected to a wifi or cellular network.
    Unfortunately, you cannot activate iCloud or 'Find My Phone' remotely.

  • What are Parameters? How are they differenet from Variables? Why can't we use variables for passing data from one sequnece to another? What is the advantage of using Parameters instead of Variables?

    Hi All,
    I am new to TestStand. Still in the process of learning it.
    What are Parameters? How are they differenet from Variables? Why can't we use variables for passing data from one sequnece to another? What is the advantage of using Parameters instead of Variables?
    Thanks in advance,
    LaVIEWan
    Solved!
    Go to Solution.

    Hi,
    Using the Parameters is the correct method to pass data into and out of a sub sequence. You assign your data to be passed into or out of a Sequence when you are in the Edit Sequence Call dialog and in the Sequence Parameter list.
    Regards
    Ray Farmer

  • Hi.  I recently purchased 2 ringtones from itunes store.  When l asked the sysem provider to transfer my data from old phone to the new iphone 5, it gets override.  When i try to download the same ringtones, it asked for me to purchase again.  Pls help

    Hi. l recently purchased 2 ringtones from itunes store. When l asked the system provider to transfer my data from old phone to the new iphone 5, it gets override.  When i try to downloa the same ringtone again, l was asked to purchase it again. Please help tks

    You only get one download.
    Did you fail to save your ringtones to your computer?

  • Can anyone help me with the commands to import and restore  backup from  another administrative server

    Dear all.
                         Can anyone help me with the commands to import and restore  backup from  another administrative server

    I tried, even with code tags it looks the same since the 2500 character limit is exceeded.
    Please post just the relevant parts inside tags as mentioned, and choose a descriptive subject line.
    I'm locking this thread.
    Thomas

Maybe you are looking for

  • Adobe Photoshop CS6 won't run, problem with Application Manager

    I've now got three Adobo Photoshop CS products on my MacBook Pro, the latest is CS6 which won't run. I own Photoshop CS3, I just happen to install the CS5.x suite today, which runs during the trial period (30 day, today is day #1). I then see that PS

  • Long time to print to pdf

    In adobe framemaker 8, my coworkers and I print book files which are 200-300 pages long with about 10-15 figures. The problem is that it takes me 4 mintues to print it, one coworker takes 30 minutes to print and another coworker 3 hours to print the

  • Winocc.cpp line 329 - using CWGraph in MFC OCX project

    I'm trying to create my own custom ActiveX control for use in a third party application.  My control consists of a dialog window (CDialog derived) that I use for data display.  This works fine, but if I drop a CWGraph control onto my dialog, the cont

  • HTML form to clob

    Hi all i have an oracle 9i database. One of the application is used to store data given through standard HTML forms (not oracle forms). These are stored in varchar2 fields and all works fine. However we now have a new request that would require one o

  • Website elements out of alignment

    I have a new computer, new install of firefox, there are some webpages that do not have the correct alignment. As if there is a compatibility issue. I'm a project manager for a web development company, and I have some websites where the alignment of