Ask Experts Questions for FREE Help!
  Advanced
Register  |  Log in  
   Ask    
 Answer  
  Help  

Ask QuestionsprogressAnswer QuestionsprogressBuild ReputationprogressBecome an Expert
 
Free Answers in 3 Easy Steps

Register Now
3 Steps

At Ask Me Help Desk you can ask questions in any topic and have them answered for free by our experts. To ask questions or participate in answering them you must register for a free account. By registering you will be able to:
  • Get free answers from experts in any of our 300+ topics.
  • Accept money for answers that you provide.
  • Communicate privately with other members (PM).
  • See fewer ads.

Home > Computers & Technology > Software > Utilities   »   dynamic jsp

 
Question Tools Search this Question Display Modes
Question
 
 
#1  
Old Feb 22, 2006, 07:45 AM
sarah11282
Junior Member
sarah11282 is offline
 
Join Date: Jun 2005
Posts: 56
sarah11282 See this member's comment history on his/her Profile page.
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

Reply With Quote
 
     

Answers
 
 
Old Feb 23, 2006, 10:26 AM   #2  
LTheobald
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
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.
  Reply With Quote
 
     
 
 
Old Feb 24, 2006, 12:25 AM   #3  
LTheobald
Ultra Member
LTheobald is offline
 
LTheobald's Avatar
 
Join Date: Feb 2004
Location: Cambridge, UK
Posts: 1,047
LTheobald See this member's comment history on his/her Profile page.LTheobald See this member's comment history on his/her Profile page.
Call LTheobald via Skype™ Send a message via MSN to LTheobald
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.
  Reply With Quote
 
     


Question Tools Search this Question
Search this Question:

Advanced Search
Display Modes

 
Similar Sponsors

Similar Questions
Question Asker Topic Answers Last Post
Dynamic IP Rithy69 Networking 1 Sep 14, 2007 07:44 AM
archiving dynamic web sites meidaan Internet & the Web 1 Jul 27, 2006 12:03 AM
Changing Dynamic IP address to Static... Flintstones1962 Networking 5 Jan 24, 2006 11:41 PM
question about dynamic ip thetachi464 Internet & the Web 11 Oct 25, 2005 01:14 PM
Static - Dynamic systems in airliners shanus Aviation 0 Oct 21, 2004 07:19 AM




Copyright ©2003 - 2007, Ask Me Help Desk.
All times are GMT -8. The time now is 11:04 PM.

Content Relevant URLs by vBSEO 3.0.0 RC6 © 2006, Crawlability, Inc.