• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Initialization in doPost

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi i am trying to initialize parameters in doPost() method but the variables does'nt seem to get initialized.can anybody please help me???
My code looks like this
package Bidder.Agent;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import AuctionEngine.*;
public class agentFactory extends HttpServlet implements Runnable{
public String AuctionID=null;
public String Quantity=null;
public String User=null;
public String MPrice=null;
public void doPost(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
response.setContentType("text/html");
PrintWriter out=response.getWriter();AuctionID=request.getParameter("ActID");
Quantity= request.getParameter("Qty");
User= request.getParameter("user");
MPrice= request.getParameter("Maxprice");
agentFactory aF=new agentFactory();
Thread t=new Thread(aF);
t.start();
out.println("AgentRunning");
}
public void run()
{
System.out.println(AuctionID);
SetAgent ag=new SetAgent();
ag.initialize(AuctionID,Quantity,User,MPrice);
}

}
 
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is your current output:
AgentRunning
null
 
roopa sudhi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes. Browser displays "Agent Running" but the agent throws null pointer exception as Auction ID is null. I am unable get the initialized values in run() method.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your approach is fraught with difficulties that will prevent this design from working with more than a single user at a time. All sorts of bizarre things will happen when more than one person sends a request to the servlet. You need to study basic servlet design principles.
As far as your immediate problem goes, every time you get a parameter from the request, you should check it for a null value. I bet there is some difference between the names of the parameters your form creates and the names you are asking for.
Bill
 
roopa sudhi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the advice i'll work on the basics.I still have a doubt.
This is what i was trying to accomplish
when a bidder sets an agent, request should be sent to invoke the agent and he should be able to continue browsing.The parameters names are correct because if i print the value of AuctionID in doPost() my browser shows the correct answer but if i use the same variable in the run method which gets initialized in the doPost method it shows null.
 
Michael Pearson
Ranch Hand
Posts: 351
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should review the Factory Pattern.
Factory
Let's try to simplify this..
Why not create a Bid object that contains the information entered by a unique user for a unique auction item?
You may want to store this Bid in a collection for the Auction the user is bidding on. Somehow this data needs to persist.
 
roopa sudhi
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your kind reply michael
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic