Monday, October 19, 2009

Access the url parameter from IBM WebSphere Portal V6.1 by using RunData

Here I have simple Portlet Code.

public void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {

String phoneId = getparamter("PhoneId" request);
}

private String getparamter(String key, RenderRequest request) {
String value = null;

try {
RunData rd = RunData.from((ServletRequest) request);
String strURL = rd.getRequestURL();
log.info("Request URL is " + strURL);
String strSplit = strURL.substring(strURL.indexOf('?') + 1);
log.info("Parameter URL is" + strSplit);
StringTokenizer tokenizer = new StringTokenizer(strSplit);
while (tokenizer.hasMoreElements()) {
String token = (String) tokenizer.nextElement();
if (token.indexOf(key) != -1) {
value = token.substring(token.indexOf("=") + 1);
break;
}
}
log.info("key value in getparamter :" + value);
if (value.indexOf("&") > 0) {
value = value.substring(0, value.indexOf("&"));
log.info("Parameter URL is" + value);
}
} catch (Exception e) {
log.error("No value retrieved from URL");
e.printStackTrace();
}
return value;
}

No comments:

Post a Comment

Followers