Ananth,
A couple of comments on your code:
1) I am almost certain that the method should not be synchronized.  There
aren't any variables or data structures that are being used that are shared.
2) It is a bad practice to have a data structure like HttpServletRequest as
a parameter to a domain object especially when the only value used from the
data structure is the value of the String returned by the
req.getParameter("TOWHERE") method call.  This practice is called "Exposing
Presentation-Tier Data Structures to Domain Objects" from pg. 51 of Core
J2EE Patterns)  The reason this is a bad practice is that it needlessly
couples two distinct aspects of the application.  It also limits the
ability for the function to be reused  b/c it makes the function protocol
or tier-specific.  In this case, the req variable could just be replaced by
a String variable called toWhere or another meaningful name.
3) The counter variable is being used just as a flag and should therefore
be replaced with a boolean.
4) There are several instances where you use 'new String("displayHeader")'
.  I think all of these can be replaced with just "displayHeader".
5) The getOrPost int parameter should just be a boolean since it only has
two values. Constants.HTTP_GET or Constants.HTTP_POST.  A more meaningful
name for the variable would be isPost or isGet.  It would make the code
more understandable
6) The parametersOutput variable seems to be unused unless there was
additional code that you cut.  It seems to me that this variable is getting
appended to itself repeatedly.  You might want to put a
System.out.println("parametersOutput = " + parametersOutput); in your code
to see what the value is.
7)  The entire function can be distilled to the following:

>private void fillSetHeaderProperty(HashMap map, String toWhere,boolean isGet)
{
         int i = 0;
         toWhere = toWhere.trim();
           if (isGet)
                 toWhere = toWhere + ".GET";
           else
                 toWhere = toWhere + ".POST";
           while (i<Constants.RESTRICT_HEADER_DISPLAY.length)
           {
                 if
(toWhere.equals(Constants.RESTRICT_HEADER_DISPLAY[i].trim()))
                 {
                         if (isGET)
>                                 map.put("displayHeader","N");
                         else
                                 map.put("displayHeader","Y");
                         break;
                 }
                 i++;
         }
         if (i == Constants.RESTRICT_HEADER_DISPLAY.length)
                 map.put("displayHeader","Y");
}



At 10:20 AM 8/24/01 +0800, you wrote:
>I have zeroed upon a simple function to depict the scenario Iam facing.
>There are multiple other functions like this..
>
>This function fills the header part of the page with parameters fetched from
>the HashMap and also depending upon the get or post method called by the
>invoker servlet.
>
>
>////////////////////Function Begin
>
>         private synchronized void fillSetHeaderProperty(HashMap map,
>HttpServletRequest req,int getOrPost)
>         {
>
>                 String tempStr=null;
>                 String toWhere=req.getParameter("TOWHERE");
>                 String tempStr1 = null;
>
>                 int counter=0;
>
>                 for(int i=0; i < Constants.RESTRICT_HEADER_DISPLAY.length;
>i++)
>                 {
>                         tempStr = Constants.RESTRICT_HEADER_DISPLAY[i];
>
>                         if(getOrPost==Constants.HTTP_GET)
>                         {
>                                 tempStr1 = toWhere + ".GET";
>                                 if
>((tempStr1.trim()).equals(tempStr.trim()))
>                                 {
>                                         map.put(new String("displayHeader"),
>"N");
>
>////////////////////////////////////////////////////////////////////////////
>/////////////////////
>
>//COMMENTED BY ANANTH   THE PARAMETERVARIABLE  I SUSPECT AND I COMMENTED
>FROM HERE
>
>
>
>//parametersOutput = parametersOutput + "<br><b>Name:</b>&nbsp;&nbsp;" + new
>String("displayHeader") + "&nbsp;&nbsp;<b>Value:</b>&nbsp;&nbsp; N" ;
>
>
>
>/////////////////////////TILL HERE
>
>
>
>                                                 counter =counter + 1;
>                                 }
>                         }
>                         else
>                         {
>                                 tempStr1 = toWhere + ".POST";
>
>                                 if
>((tempStr1.trim()).equals(tempStr.trim()))
>                                 {
>                                         map.put(new String("displayHeader"),
>"N");
>
>
>
>//COMMENTED BY ANANTH SIMILARLY HERE ALSO
>//                                      parametersOutput = parametersOutput
>+ "<br><b>Name:</b>&nbsp;&nbsp;" + new String("displayHeader") +
>"&nbsp;&nbsp;<b>Value:</b>&nbsp;&nbsp; N" ;
>
>
>                                                 counter=counter+1;
>                                 }
>                         }
>                 }
>                 if (counter==0)
>                 {
>                         map.put(new String("displayHeader"), "Y");
>
>
>//COMMENTED BY ANANTH
>//                      parametersOutput = parametersOutput + "<br><b>" +
>tempStr + "</b><br><b>" + tempStr1 + "</b><b>Name:</b>&nbsp;&nbsp;" + new
>String("displayHeader") + "&nbsp;&nbsp;<b>Value:</b>&nbsp;&nbsp; Y" ;
>
>                 }
>         }
>
>
>
>
>
>
>/////////////////Function Ends
>
>
>Suggest me whether this is the "solution" or anyother is there. So far i did
>not receive the error and the site runs pretty fast.This variable
>"parametersOutput" i was using to view the parameters of the pages I left it
>just by commenting the out.println. But the variable was getting populated
>again and again and may be it threw that error. Correct me whether the
>solution is right.
>
>thanks
>ananth
>
>___________________________________________________________________________
>To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
>of the message "signoff SERVLET-INTEREST".
>
>Archives: http://archives.java.sun.com/archives/servlet-interest.html
>Resources: http://java.sun.com/products/servlet/external-resources.html
>LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to