File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes local variables acting like class variables in JServ?? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "local variables acting like class variables in JServ??" Watch "local variables acting like class variables in JServ??" New topic
Author

local variables acting like class variables in JServ??

Manoj Pandey
Ranch Hand

Joined: May 03, 2001
Posts: 36
Hi,
I am confronted with a strange problem. I have defined some variables in the doPost method,and initialised them by request.getParameter() . I am modifying their value in the code , but the next time the doPost method is executed , I get the modified values??I am actually calling the doGet method first and the the doPost. I am not writing the modified value or saving it in the instance variables or the static variles , I think it is absolutly crazy
HERE IS THE SERVLET TAG (I am using JServ)
<servlet code="com.MindShaper.ClassTeacher.Apps.HigherEd.IIFT.Utility.QueryResultAsLink" codebase="/servlets">
<param name="table" value="INSTITUTE_CHAPTERS,IIFT_CHAPTERS">
<param name="where" value="INSTITUTE_CHAPTERS.icourse_id,icourse_id">
</servlet>
HERE IS THE CODE

public class QueryResultAsLink extends HttpServlet
{
static MSConnectionBroker connBroker;
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
doPost(req,res);
}

public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{

PrintWriter out = res.getWriter();
res.setContentType("text/html");

try{

String[] where=req.getParameterValues("where");
String[] whereVal=null;
if (where!=null)
{
whereVal=new String[where.length];
for (int i=0;i<where.length;i++)
{
int j=where[i].indexOf(",");
if(j==-1)
{
whereVal[i]=req.getParameter(where[i]);
}
else
{
String where2=where[i].substring(j+1,where[i].length());
where[i]=where11;
//IF I COMMENT OUT ABOVE LINE, I GET THE ACTUAL VALUES ELSE I GET THE MODIFIED VALUES
whereVal[i]=req.getParameter(where2);
}
}
}
else where=new String[0];
}
catch(Exception e)
{
Log.log(e);

}

}

GOD BLESS THOSE WHO HELP MEE!!!
}
[ February 01, 2002: Message edited by: manoj pandey ]

Sun Certified Java Programmer
Manoj Pandey
Ranch Hand

Joined: May 03, 2001
Posts: 36
the problem is still unresolved if anyone can find the reason plz help
Napa Sreedhar
Ranch Hand

Joined: Jan 29, 2002
Posts: 62
There are quite some problems in understanding your code.
You use req.getParameter(....) on form variables
i(j==-1) // where did you get this j
{
whereVal[i]=req.getParameter(where[i]); // where[] contains values and no form variables
}
else
{
String where2=where[i].substring(j+1,where[i].length());
where[i]=where11;
//IF I COMMENT OUT ABOVE LINE, I GET THE ACTUAL VALUES ELSE I GET THE MODIFIED VALUES
whereVal[i]=req.getParameter(where2); // why are you using again req.getParameter ? This is not at all needed.

Please check your code ...
Napa
Napa Sreedhar
Ranch Hand

Joined: Jan 29, 2002
Posts: 62
I understand the if (j === ...) part...
Explain more clearly what you are doing in your JSP ?
Napa
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: local variables acting like class variables in JServ??