Capturing Form Data in Java Servlet - Code hunting as well -
I want some feedback on a particular problem that I am trying to understand. I am trying to create a simple Java web app that will allow the user to enter his zipcode and distance, and Java will capture the servillet and run the data through the Best Buy API, BBi Open, Remix, which provided the closest information to the stores' locations. The Java APIs (provided by the BBC Open) documents present this as an example:
import java.util.ArrayList; Import java.util.HashMap; Import java.util.list; Import java.util.Map; Import com.mattwilliamsnyc.service.remix *; Public Class Remix Advancemo {Public Static Zero Main (String [] Args) {Remix Remix = New Remix ("Your Apk"); & Lt; String & gt; Storefilter = new arreelist & lt; String & gt; (); & Lt; String & gt; Product filter = new archilist & lt; String & gt; (); StoreFilters.add ("Area (1120110)"); ProductFilters.add ("sku = 8,982,988"); Try {StoreResponse response = remix.getStore Availability (StoreFilter, Product Filters); If (! Response.isError ()) (Store Store: response.list ()) {System.out.println (store.getName () + "(" + store.getDistance () + "miles)"); (Product Products: store.getProducts ()) {If (product.hasInStore availability ()) {System.out.println (product.getName ()); System.out.println ("Available for $" + product.getSalePrice ()); }} System.out.println (); }} And {error document error = response. Gear} (); If (empty! = Error) {System.out.println (error.getStatus ()); Println (error.getMessage ()); Println ("Example:"); (String example: error.getExamples ()) {System.out.println (for example); }}}} Catch (Remix Up E) {E.PintBackTrace (); }}} This is an example to find stores in New York City, in which the Playstation 3 is available which I do not want to do but I think that whatever I need is Here's a little bit of tinkering.
1.I'm assuming that I can remove any reference to Products in the code. 2. Do I need a store store filter = new Arrayist ();? Is it necessary for servlet? 3. I can use GetParameter () to retrieve user input from my .jsp form, and then store it in storeFilters.add "area (1120110)"); Already replace the values.
I am quite new to Java, and any help or advice on this would be great. Cheers
-
It seems that you can ignore some parts of the example With the deal products you only interested in places.
-
This line variable is declaring the store filter and is starting it as an empty list. So yes, this part is essential, because you are adding filters to that list later in the code. Check the documentation on the list (and arrelist): -
Yes, HTTPSveter.net.GetPameter () will assign you the string value of the form field (and query string parameters) so that you dynamically Make the filter you need and add it to the store filter list.
Comments
Post a Comment