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
Java

Avatar of undefined
Last Comment
jaggernat

8/22/2022 - Mon
Ajay-Singh

instead of setAttribute try using setParameter
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 ...
jaggernat

ASKER
The output of URL

my url should change to   ..browse.do?option=myCart
Your help has saved me hundreds of hours of internet surfing.
fblack61
jaggernat

ASKER
it doesnt show me setParameter, it only shows me setAttribute.
Is setParameter depricated?
igrahami

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.
jaggernat

ASKER
>>> 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

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
CEHJ

>>
 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
Mick Barry

you need to rebuild the entire request string, you cannot do it by modifying the requrest
ASKER CERTIFIED SOLUTION
reach2piyush

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
jaggernat

ASKER
thanks
J
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes