掲示板

How can portlet call servlet and servlet redirect to jsp

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

How can portlet call servlet and servlet redirect to jsp

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: How can portlet call servlet and servlet redirect to jsp

Liferay Legend 投稿: 14919 参加年月日: 06/09/02 最新の投稿
It cannot and should not. See my other post to this same thread.
6年前 に Rae-Wi Tan によって更新されました。

RE: How can portlet call servlet and servlet redirect to jsp

New Member 投稿: 5 参加年月日: 18/03/23 最新の投稿
where? can you provide a link
thumbnail
6年前 に Olaf Kock によって更新されました。

RE: How can portlet call servlet and servlet redirect to jsp

Liferay Legend 投稿: 6403 参加年月日: 08/09/23 最新の投稿
Rae-Wi Tan:
where? can you provide a link


Welcome to Liferay.

This was a post from 2012, touching JSR 168. Since 2008 JSR 286 is superseding JSR 168, rendering the required workarounds unnecessary.
I doubt someone will go down into the archives and find the link for you, but if you let us know your current issue, we might be able to help based on information we'd give in 2018