我是portlets的新手,我对HelloWorld应用程序有一个问题。应用程序显示所有静态内容(来自index.jsp),但HelloWorldPortlet.java中的代码根本不显示。我说的是
response.getWriter().print("Hello World Portlet!");我还在生命周期方法中放置了一些控制台日志(System.out.println),只是为了检查它,但控制台中没有显示任何内容:(
public class HelloWorldPortlet extends GenericPortlet{
public void doView( RenderRequest request, RenderResponse response )
throws PortletException, IOException {
System.out.println("doView()");
response.getWriter().print("Hello World Portlet!");
}
}我的猜测是,在众多的XML配置文件中,关于.java文件/类的某些设置是错误的。
编辑:我使用的是Maven构建工具,我对它只略知一二。
pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.journaldev</groupId>
<artifactId>HelloWorldPortlet</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>HelloWorldPortlet Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<dependency>
<groupId>org.apache.portals</groupId>
<artifactId>portlet-api_2.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.portals.pluto</groupId>
<artifactId>maven-pluto-plugin</artifactId>
<version>2.1.0-M3</version>
<executions>
<execution>
<phase>generate-resources</phase>
<goals>
<goal>assemble</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>${project.build.directory}/pluto-resources/web.xml</webXml>
</configuration>
</plugin>
</plugins>
<finalName>HelloWorldPortlet</finalName>
</build>
</project>发布于 2018-04-25 20:10:19
这应该会有帮助..。
protected void doView(RenderRequest request, RenderResponse response)
throws PortletException, IOException, UnavailableException
{
response.setContentType(request.getResponseContentType());
PortletRequestDispatcher dispatcher = getPortletContext().getRequestDispatcher((new StringBuilder("/WEB-INF/jsp/TestPortlet")).append(VIEW).toString());
dispatcher.include(request, response);
}
public void processAction(ActionRequest request, ActionResponse response)
throws PortletException, PortletSecurityException, IOException
{
String name = request.getParameter("firstname");
if(name != null && !name.equals(""))
response.setRenderParameter("helloname", name);
}
public static String VIEW = "/view.jsp";
public static final String PORTLET = "TestPortlet";在jsp中,您可以使用...
String requestParameter = request.getParameter("helloname"); https://stackoverflow.com/questions/49795652
复制相似问题