Link to home
Start Free TrialLog in
Avatar of jaggernat
jaggernat

asked on

set value in request

Dear Experts

I have a url like this ..browse.do?option=reports

In my java class i am doing this

if (request.getParameter("option") != null) {
            String changetoMyCartAdd = request.getParameter("option");
            if(changetoMyCartAdd.equals("reports"))
            {
            
                  request.setAttribute("option","myCart");
                  request.setAttribute(changetoMyCartAdd,"myCart");
                  
                  //Here i want to change reports to myCart
                  
            }

My final output should be  option=myCart  i.e.  value of option  should be myCart

the above code doesnt work. any ideas


thanks
J
Avatar of Ajay-Singh
Ajay-Singh

instead of setAttribute try using setParameter
Avatar of CEHJ
>>My final output should be  option=myCart

The output of what? Sounds more like you need to call respone.sendRedirect with the url you want to me ...
Avatar of jaggernat

ASKER

The output of URL

my url should change to   ..browse.do?option=myCart
it doesnt show me setParameter, it only shows me setAttribute.
Is setParameter depricated?
Attributes and Parameters are different things and you can't change the value of parameters you can only change the values of attributes. Why are you trying to change a parameter value? If you are wanting to use the changed value later on just use the attribute value that you changed.
>>> just use the attribute value that you changed

what ever i changed doesnt work

 request.setAttribute(changetoMyCartAdd,"myCart");
although i set it using above statement
changetoMyCartAdd still has the value reports. i want changetoMyCartAdd to be "myCart"

or option=myCart

>>
 The output of URL

my url should change to   ..browse.do?option=myCart
>>

URLs don't have outputs. You need to response.sendRedirect from one to the other as i mentioned earlier
you need to rebuild the entire request string, you cannot do it by modifying the requrest
ASKER CERTIFIED SOLUTION
Avatar of reach2piyush
reach2piyush
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks
J