Jump to content

If you are looking for a challenge here is.. (JSP and java class)

- - - - -

  • Please log in to reply
13 replies to this topic

#1
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Ok, thats very very weird. Im calling a java method in JSP that just decrease a value once and update an XML file. Problem is that instead of decrease it once, decreace it twice! Putted some System.out in my method one after value decreased and one at the end of method. When i click submit in tomcat window i have

Item decreased

Item decreased

End of method

End of method
Method is called just once from one place, FOR SURE! I and my tutors couldn't find the reason. However at the very first time, where TOMCAT starts when i submit i have

Item decreased

End of method
but page crashed with EOFexception.
I don't know really what happening. Anyone, any idea?

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#2
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Without seeing the code, no clue.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#3
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Ok here is:
Method in java class

public void newQuantity() throws Exception{

		Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(

		new InputSource("c://apache-tomcat-6.0.29/webapps/ROOT/Milestones/store.xml"));

		

		for(int i=0; i<purchase.size(); i++){

			Purchase dlPurchase = (Purchase) purchase.get(i);

         

			XPath xpath = XPathFactory.newInstance().newXPath();

			NodeList node = (NodeList) xpath.evaluate(("/madShop/category/goodsItem[name='"+dlPurchase.getItem()+"']/quantity"), doc,XPathConstants.NODESET);

			

			System.out.println(dlPurchase.getItem());

			

			int quantity = Integer.parseInt(node.item(0).getTextContent());

			node.item(0).setTextContent(Integer.toString(quantity -1));

		}

		Transformer xformer = TransformerFactory.newInstance().newTransformer();

		FileOutputStream outStream = new FileOutputStream(new File("c://apache-tomcat-6.0.29/webapps/ROOT/Milestones/store.xml"));

		xformer.transform(new DOMSource(doc), new StreamResult(outStream));

		

		outStream.flush();

		outStream.close();

		

		this.saveMe();

		System.out.println("END");

}

And my JSp page:

PurchaseManager purchaseManager = new PurchaseManager("H:\\MadshopUsers\\purchase.obj");


if(checkout!=null){

	purchaseManager.newQuantity();

	purchaseManager.clearAll();

}



<a href="purchare.jsp?checkout=all"><button class="alt" style="top:350px; right:200px;"><img src="purchareBt.jpg" border=0 width="100" height="40"/></button></a>


"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#4
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java

toto_7 said:

However at the very first time, where TOMCAT starts when i submit i have

Item decreased

End of method
but page crashed with EOFexception.
I don't know really what happening. Anyone, any idea?

This would indicate that there's nothing wrong with the newQuantity method, as otherwise you wouldn't even see "END" there. Meaning it happens at clearAll(), or even lower in the code we don't see.

#5
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
Here is my clearAll():


public void clearAll() throws IOException{

	purchase.clear();

	this.saveMe();

}

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#6
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
What does saveme() do?

#7
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts

private void saveMe() throws IOException

	{

		FileOutputStream fileOut = new FileOutputStream(this.filename);

		ObjectOutputStream objectOut = new ObjectOutputStream(fileOut);

		objectOut.writeObject(this.purchase);

		objectOut.close();

	}

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#8
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
I also find it pretty weird to have a <button> inside an <a> tag, can you see what it does without the <button>, just <img> inside <a>?
(Also try flush() before closing in saveMe())

#9
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
nothing changed, still the same problem

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#10
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Okay, nothing else to do with the code you provided :P

#11
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
My tutors had all of the code and didnt find it also :P

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz

#12
toto_7

toto_7

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 295 posts
OK!! First you are mastermind, second explain me why please.
I didnt notice what you said me about <button> in a <a>, removed now and is perfect.
Why that was happening??

"Programming is like sex. One mistake and you have to support it for the rest of your life."

-Michael Sinz




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users