Im tring to update my shopping webpage. I have 3 JSPs (main page - list of goods - good page). The main idea, click a category to main page, transfer you to list of correspoding goods and then click on good's name and transfer you to good page. Until now is working but i wanna make it more efficiency because in good page JSP, compile for each item name, image, price from XML file again and again and again.
Example:
if(request.getParameter("good").equals("1")){
groName = xpath.compile("/madShop/category[@id='Grosery']/goodsItem[2]/*[3]");
grosNmNode = groName.evaluate(dom, XPathConstants.NODESET);
nodeGrosNm = (NodeList) grosNmNode;%>
<img src="<%=nodeGrosNm.item(0).getTextContent()%>" height="148" width="198" ondblclick="height='148'; width='198'; border='0';" onclick="height='248'; width='298'; border='2';" style="position:fixed; top:210; left:30;"/>
<%groName = xpath.compile("/madShop/category[@id='Grosery']/goodsItem[2]/*[1]");
grosNmNode = groName.evaluate(dom, XPathConstants.NODESET);
nodeGrosNm = (NodeList) grosNmNode;%>
<h2 style=" color:#006600; position:fixed; left:400; top:200;"><%=nodeGrosNm.item(0).getTextContent()%></h2>
<%groName = xpath.compile("/madShop/category[@id='Grosery']/goodsItem[2]/*[2]");
grosNmNode = groName.evaluate(dom, XPathConstants.NODESET);
nodeGrosNm = (NodeList) grosNmNode;%>
<h6>Price: £<%=nodeGrosNm.item(0).getTextContent()%>/kg</h6>
<%}%>
I have 15 items, so im doing this 15 times. Bad coding i know :S As you can see from if statement, i gave to each item unique id number, so i thought use it inside compiler
int goodId = Integer.parseInt(request.getParameter("good"));
<%groName = xpath.compile("/madShop/category[@id='Grosery']/goodsItem[goodId]/*[2]");
grosNmNode = groName.evaluate(dom, XPathConstants.NODESET);
nodeGrosNm = (NodeList) grosNmNode;%>
...but always show me the first item's details
HELP PLEASE


Sign In
Create Account


Back to top









