0
我是Java EE的新手,對它還不太瞭解。Java EE添加條目...邏輯問題?
我們是奉命保存使用HashMap中的條目,但我問題是我不知道如何讓一個類閱讀我的servlet弦數
這是我Servelet的代碼:
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 am planning to call a method from my DataServClass
like:
Item item = service.AddData(id);
--> not really sure with what i am doing <--
*/
}
}
這是我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 is what i am planning to do but don't know what to key should i replace with
"this"
--> itemList.put(this, this);
*/
}
public Item retrieveData(String id) {
if (itemList.containsKey(id)) {
Item item = (Item) itemList.get(id);
return item;
}
return null;
}
}
我也在想會議的用法......但是還是不知道該怎麼申報......希望你能幫助我......多謝多謝
thnx partenon^_ ^ – iamanapprentice 2011-03-02 14:23:26