掲示板

portlet call servlet but servlet redirect to jsp doesn't work !!!!!!!!!

thumbnail
12年前 に behnaz eslami によって更新されました。

portlet call servlet but servlet redirect to jsp doesn't work !!!!!!!!!

Junior Member 投稿: 54 参加年月日: 11/11/14 最新の投稿
I have a JSR168 portlet. I want to call a servlet on it.

1 ) in doview - I dispatch to my servlet that I created it before.
Now I want to , in my servlet - in doGet part , dispatch to a jsp page.

Part one is ok(means : dispatch portlet to servlet) but I have problem with second part, when I want to dispatch in my servlet to a .jsp file.

Please guide me.

here is my code:

============================================================
view.jsp

<%@ page import="javax.portlet.PortletPreferences" %>
<%
/**
* Copyright (c) 2000-2009 Liferay, Inc. All rights reserved.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
%>

<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>

<portlet:defineObjects />

<% PortletPreferences prefs = renderRequest.getPreferences(); %>
<form action="<portlet:actionURL/>" method="post" class="uni-form">

<input type = "text" name="<portlet:namespace/>text" value="test-value"/>

<input type="submit" name = "<portlet:namespace/>submit" value="12345"/>

</form>
============================================================
JSPPortlet - doView part

protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException {
response.setContentType("text/html");
PortletPreferences prefs = request.getPreferences();

System.out.println("**************************************");

System.out.println(request.getParameter("text"));
String x = request.getParameter("text");
System.out.println("X = " + x);

if((null == x) || ("" == x))
{
System.out.println("x is null.");
PortletRequestDispatcher dispatcher1 = getPortletContext().getRequestDispatcher("/WEB-INF/jsp/view.jsp");
dispatcher1.include(request, response);
}
else{
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher("/DisplayImg");
dispatcher.include(request, response);
System.out.println("inja elseeeeeeeeeeee view"+request.getParameter("text"));
}

}

============================================================

servlet - doGet

public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
PrintWriter out = response.getWriter();
out.println("Hello, this is a servlet!!!");
out.println(request.getParameter("text"));
RequestDispatcher dispatcher = request.getRequestDispatcher("/WEB-INF/jsp/showImg.jsp");
dispatcher.forward(request,response);
}

my problem is in highlighted part.
============================================================
thumbnail
12年前 に David H Nebinger によって更新されました。

RE: portlet call servlet but servlet redirect to jsp doesn't work !!!!!!!!!

Liferay Legend 投稿: 14915 参加年月日: 06/09/02 最新の投稿
First of all whatever you're doing, it's just wrong.

From a portlet, you would call a servlet to do something, but not rely upon it to do any sort of redirection or anything like that. Ultimately the portlet is responsible for rendering it's content and managing it's flow, not some secondary servlet.

Ultimately your code is bound to break because servlets expect to be able to just write to the response stream, but since the portal has already started writing to the stream before the portlet gets it, you're bound to run into issues.

If you do not want to refactor your code out of the servlet, perhaps you should explore the web proxy portlet or the iframe portet.