This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes Initialization in doPost Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Initialization in doPost" Watch "Initialization in doPost" New topic

Initialization in doPost

roopa sudhi

Joined: Oct 31, 2001
Posts: 16
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 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{
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);
public void run()
SetAgent ag=new SetAgent();

Michael Pearson
Ranch Hand

Joined: Mar 11, 2001
Posts: 351
Is your current output:
roopa sudhi

Joined: Oct 31, 2001
Posts: 16
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.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13027
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.
roopa sudhi

Joined: Oct 31, 2001
Posts: 16
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

Joined: Mar 11, 2001
Posts: 351
You should review the Factory Pattern.
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

Joined: Oct 31, 2001
Posts: 16
Thanks a lot for your kind reply michael
I agree. Here's the link:
subject: Initialization in doPost
It's not a secret anymore!