java EE adding entry...logical problem? -


i new @ java ee , still not familiar it.

we instructed save entry using hashmap, problem don't know how let class read few strings servlet

this servelet code:

import java.io.ioexception; import javax.servlet.requestdispatcher; import javax.servlet.servletexception; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletrequest; import javax.servlet.http.httpservletresponse;  public class adddata extends httpservlet {      public void doget(httpservletrequest request,             httpservletresponse response)             throws servletexception, ioexception {          string id = request.getparameter("newid");         string name = request.getparameter("newstockname");         string uprice = request.getparameter("newuprice");         string onstock = request.getparameter("newonstock");          dataservclass service = new dataservclass();          /*i planning call method dataservclass           like:           item item = service.adddata(id);           --> not sure doing <--         */      } } 

this dataservclass:

public class dataservclass {     hashmap itemlist = new hashmap();     public dataservclass() {         itemlist.put("bpen", new item( "bpen", "ballpen", 5.50, 400 ));         itemlist.put("bonda4", new item( "bonda4", "a4 bondpaper", 250.00, 35 ));         itemlist.put("pclip22", new item( "pclip22", "paperclip no.22", 15, 30 ));         itemlist.put("cd", new item( "cd", "blank cd", 4.50, 550 ));      }     public void adddata(){         /*this planning don't know key should replace             "this"           --> itemlist.put(this, this);          */     }      public item retrievedata(string id) {         if (itemlist.containskey(id)) {             item item = (item) itemlist.get(id);             return item;         }         return null;     } } 

i thinking of usage of session... still no idea how declare it... hope can me... lot

there few things not clear. instance:

save entry using hashmap

what "save" means in context? persist value in database? also, it's not clear why want use session.

anyway, add "item" have in servlet itemlist, can this:

// in servlet item item = new item(id, name, unprice, onstock); service.adddata(item);  // in dataservclass public void adddata(item item){   itemlist.put(item.getid(), item); } 

a non-related note: please, try follow java naming conventions (like, methods starting lower case). can omit "class" part of class dataservclass ;-)


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -