cancel
Showing results for 
Search instead for 
Did you mean: 

How to use Cookies in Web DynPro?

Former Member
0 Kudos

Hello,

Is there a way to use Cookies in Web DynPro like a regular Servlet uses in it's response Object?

If yes, I could use a code example...

Roy

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

You could use the Cookies class but it would be a non standard API for WebDynpro.

Code would be something like

Cookie[] cookies = request.getCookies();

String cookieName = SAPCookie;

String defaultValue = 1;

for ( int i=0; i<cookies.length; i++) {

Cookie cookie = cookies<i>;

if (cookieName.equals(cookie.getName()))

return(cookie.getValue());

}

return(defaultValue);

}

regards

Ravi

Former Member
0 Kudos

Hey Ravi,

I am familiar with this code but I don't have a request Object at DynPro, how can I create this object based on the Client's request?

Former Member
0 Kudos

Hi Roy,

Use the following code to get the request object

HttpServletRequest request =((com.sap.tc.webdynpro.services.sal.adapter.core.IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();

Regards,

Santhosh.C

Former Member
0 Kudos

10q Santhosh, 3 questions:

1. This will get a Request Object containing all the client's request data just like in a regular Servlet or does it have special considerations I should worry about?

2. Where do you recommend putting this statement? I assume at the wdDoInit() method right?

3. Is there a Response object I can create as well?

Roy

Former Member
0 Kudos

Hi Roy,

1. This will create a Request Objec containing all the client's request just like in a regular Servlet or does it have special considerations I should worry about?

A: If you have portal and webdynpro components, both have to use the same runtime. If you are using only webdynpro components then you can use the "Task" class. But it is a non-standard API.

Task.getCurrentTask().getWebContextAdapter().getHttpServletRequest()

2. Where do you recommend putting this statement? I assume at the wdDoInit() method right?

A: Don't put this statement in the doInit(), if you are handling some event within the component and refreshes the view, your doInit() will not get executed.

3. Is there a Response object I can create as well?

A:


HttpServletResponse response =((com.sap.tc.webdynpro.services.sal.adapter.core.IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletResponse()

Regards,

Santhosh.C

Former Member
0 Kudos

Simply don't do this.

Armin

Former Member
0 Kudos

Hey Armin,

Simply don't do what? use Cookies in DynPro? Than how do you suggest to acheive the same functunality Cookies give me with DynPro?

Former Member
0 Kudos

Simply don't use non-API methods.

Armin

Answers (0)