Ask Experts Questions for FREE Help !
Ask
    sarah11282's Avatar
    sarah11282 Posts: 54, Reputation: 7
    Junior Member
     
    #1

    Feb 22, 2006, 09:45 AM
    Dynamic jsp
    Hi:)

    I am doing a project where I have set up a website. I have added info into mysql.
    How do I dynamically get info.

    I have set up a clothes website, and if the customer uses drop down menus and selects "skirts" and "black" for example, how do I dynamically add the "skirts" and "black" into my sql query, rather than having to manually type them in (using jsp) which would not work anyway as obviously I don't know what the customer will want to view.

    Hope you understand what I'm asking, I'm not extactly great at computer:)

    Any help or links would be greatly appreciated,

    Thanks:)
    LTheobald's Avatar
    LTheobald Posts: 1,051, Reputation: 127
    Ultra Member
     
    #2

    Feb 23, 2006, 12:26 PM
    Hi Sarah,

    I'll answer your question with more detail tomorrow (when I have more time) but here's the jist of it.

    Your dropdown fields will need a onChange event (e.g. <select onChange="dothis">). This onchange should then submit the form. That will put what the user selected in the request context. Then all you need to do is use request.getParameter("fieldname") to get the value of whatever was in field name. Then you just use that value to build your SQL.

    I know that probably doesn't help. Check the site again tomorrow and I would have posted back a response or someone will beat me to it :) Just can't do it this evening as I'm busy.
    LTheobald's Avatar
    LTheobald Posts: 1,051, Reputation: 127
    Ultra Member
     
    #3

    Feb 24, 2006, 02:25 AM
    OK, so here's the easiest way to do this...

    You've got a webpage with a form like below:
    Code:
    <form method="post" action="test.jsp" name="productForm">
        <select name="skirts">
            <option value="skirtA">SkirtA</option>
            <option value="skirtB">SkirtB</option>
            <option value="skirtC">SkirtC</option>
        </select>
        <select name="colour" onchange="document.productForm.submit()">
            <option value="black">Black</option>
            <option value="white">White</option>
            <option value="brown">Brown</option>
        </select>
    <form>
    The onChange on the colour drop down should submit the form. You need to make sure that the "action" in the form tag points you the current JSP. So if the file with this code in is called test.jsp, the action should point to test.jsp.

    Then at the top of this page somewhere you want some code similar to the following:
    Code:
    <%
        // Retrieve the selected skirt & colour
        String skirtType = request.getParameter("skirt");
        String colour = request.getParameter("colour");
    
        // Make sure these aren't null
        if ((skirtType != null) && (colour != null)) {
            // Form the SQL statement
            String sql = "SELECT * FROM SKIRTS WHERE ";
            sql += "SKIRT = "+ skirtType +" AND ";
            sql += "COLOUR = "+ colour;
    
            // Now you have a SQL statment containing the details of the
            // selected skirt.  Now use the sql variable to query the database.
            // I'm afraid you'll have to figure out that bit yourself though ;)
        }
    %>
    If you have any questions about the above code - post a reply here. I'll answer as soon as possible.

Not your question? Ask your question View similar questions

 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.


Check out some similar questions!

Dynamic IP [ 1 Answers ]

Hi all the Experts,

Archiving dynamic web sites [ 1 Answers ]

I look for an application that can, copy archive and export, dynamic web sites for later offline browsing. I need a better solution.

Changing Dynamic IP address to Static... [ 5 Answers ]

Hello, My question may seem very strange, but I've heard from a friend that I can change my Dynamic IP address assigned to me from ISP to Static without paying extra charges to the company. Is this possible ? Greetings,

Question about dynamic ip [ 11 Answers ]

I am wondering if there is a free program out there that I can use that will make my system act as if it has a static ip. I don't to host a site for the public it will be a site that I can go to get things for myself. I am thinking of having a ftp server so that I can access it from my friends...


View more questions Search