WebSphere Portal Server - Article by Joey Bernal on Websphere Portal Programming

This is Interesting: Free IT Magazines  
Home > Archive > WebSphere Portal Server > December 2006 > Article by Joey Bernal on Websphere Portal Programming





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Article by Joey Bernal on Websphere Portal Programming

2006-12-04, 7:22 am

Hi All,

I need your help portal experts.I had been goin through this article by Joey Bernal.
http://www-128.ibm.com/developerwor...411_bernal.html

This article mentions that in order to invoke a servlet from a portal page deployed in the same war file use the hyperlink:
<a href="<%=response.encodeURL("/TestServlet")%>" target="_blank">Launch Test Servlet</a>

I have a servlet for "writing data into a word file" and want to invoke it using the above hyperlink but when i try doing that i get the error "page not found".
But guide me how can i invoke my servlet from my portlet.
Using Websphere Portal Server 5.1.0.3 and Faces Portlet.

Best Regards,
Pallavi
Marc van Glabbeek

2006-12-04, 7:22 am

Hi,

I would use <a href="<c:out value="${renderRequest.contextPath}" />/TestServlet">link</a>

Or without JSTL: <a href="<%=portletRequest.getContextPath()%>/TestServlet">link</a>

Regards, Marc
Marc van Glabbeek

2006-12-04, 7:22 am

Hi,

I would use &lt;a href="&lt;c:out value="${renderRequest.contextPath}" /&gt;/TestServlet"&gt;link&lt;/a&gt;

Or without JSTL: &lt;a href="&lt;%=portletRequest.getContextPath()%&gt;/TestServlet"&gt;link&lt;/a&gt;

Regards, Marc

2006-12-04, 7:22 am

Hi Marc,

Thank you for your reply.
I have tried using both the links that you suggested.
a)<a href="<c:out value="${renderRequest.contextPath}" />/TestServlet">link</a>

Exception thrown in console as: com.ibm.wps.engine.Servlet doGet() class com.ibm.wps.state.nls.exceptions.NlsCannotInterpretCodecException: EJPEI0073E: The input mediator class com.ibm.wps.state.inputmediators.WPInputMediator@342948402 could not interpret
codec <c:out value= for request com.ibm.wps.engine.PortalRequestWrapper@4d917a34.

b)<a href="<%=portletRequest.getContextPath()%>/TestServlet">link</a>
Error on page: portletRequest cannot be resolved.I have included the <portlet:defineObjects /> in my portlet.

My Servlet Code is:
public class WordServlet extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String filen = "myFile.doc";
String myTextArea = "This is my data that i write into word";
response.setContentType("application/vnd.ms-word");
response.setHeader( "content-disposition","attachment;name=\""+filen+"\";filename=\""+filen+"\"");
response.setHeader("Cache-Control", "no-cache");

try{
byte[] buf=new byte[4*1024];
InputStream inStream=new ByteArrayInputStream(myTextArea.getBytes());
OutputStream outStream=response.getOutputStream();
int sizeRead;
while ( ( sizeRead=inStream.read(buf, 0, buf.length) ) != -1 )
{
outStream.write(buf, 0, sizeRead);
}
inStream.close();
outStream.close();

}
catch(IOException ex){ ex.printStackTrace();}
}
}

I would be grateful if you could help me.

Best Regards,
Pallavi

Marc van Glabbeek

2006-12-04, 7:22 am

According to your stacktrace, you are using the IBM API. The code I wrote is using the JSR 168 Portlet API. Try to replace 'renderRequest'.

Marc
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com