Hello(world) again men :)
I tried to test an helloworldPortlet with servlet/JSP but...
Well... that didn't work for me... I must have missed something important i
think... it must be a stupid error, but i don't see it...
I'm a newbie in java world so i don't really understand all what i make :-/
So, i'll describe what i have done and i'm begging for some helps plz.
I'm sure that when i'll undestand how the relation between portlet and JSP
works, i'll succeed in developping some portlets alone.
So i have an helloworld.war file constituted like that:
| -helloworld.war
| |--WEB-INF
| |--all xml files at the root of the WEB-INF directory
| |--jsp
| | |--helloworld.jsp
| |--classes
| |--gontouf
| |--helloworld
| |--servlet
| |--Helloworld.class
| |--MonPortlet.class
|
the code of my servlet(HelloWorld.java) is:
package gontouf.helloworld.servlet;
|
| import java.io.*;
|
| import javax.servlet.*;
| import javax.servlet.http.*;
| public class HelloWorld extends HttpServlet {
| public void doGet(HttpServletRequest req, HttpServletResponse resp)
| throws IOException, ServletException
| {
|
| String monNom ="FGO";
| String nom ="anotherFGO";
| resp.setContentType("text/html");
|
| req.setAttribute("monNom",monNom);
| req.setAttribute("nom",nom);
|
getServletContext().getRequestDispatcher("/helloworld.jsp").forward(req,resp);
|
|
| }
The code of my jsp file is:
<%
| String nom=(String)request.getAttribute("nom");
| String monNom=(String)request.getAttribute("monNom");
| if(nom==null) nom="inconnu";
| if(monNom==null) monNom="toujoursInconnu";
| %>
|
| <html>
| <head>
| <title>Just Hello</title>
| </head>
| <body>
|
| Hello
| <h6><%= nom %></h6>
| <h6><%= monNom %></h6>
|
| </body>
| </html>
|
|
the code of my Portlet MonPortlet is:
| package gontouf.helloworld.servlet;
|
| import java.io.IOException;
|
| import javax.portlet.GenericPortlet;
| import javax.portlet.PortletException;
| import javax.portlet.PortletRequestDispatcher;
| import javax.portlet.RenderRequest;
| import javax.portlet.RenderResponse;
|
| public class MonPortlet extends GenericPortlet {
|
| protected void doView(RenderRequest req, RenderResponse resp)
| throws PortletException, IOException {
|
| String startJSPPage =
getPortletConfig().getInitParameter("hellopage");
| PortletRequestDispatcher rdisp = getPortletContext()
| .getRequestDispatcher(startJSPPage);
| rdisp.include(req, resp);
|
| }
| }
|
|
the couple servlet/jsp works very well, but when i want to put the content of
them in the portlet, i have an error and that don't run.
ERROR MESSAGE:
anonymous wrote : 2005-07-12 11:05:11,585 ERROR
[org.jboss.portal.core.servlet.CoreServlet] Error
| java.lang.IllegalStateException: No content type defined
| at
org.jboss.portal.server.output.FragmentResult.getWriter(FragmentResult.java:93)
| at
org.jboss.portal.portlet.impl.RenderResponseImpl.getWriter(RenderResponseImpl.java:81)
| at
org.jboss.portal.portlet.impl.DispatchedHttpServletResponse.getWriter(DispatchedHttpServletResponse.java:118)
| at
javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:111)
| at
org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:124)
| at
org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:117)
| at
org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:183)
| at
org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:115)
| at
org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
| at
org.apache.jsp.WEB_002dINF.jsp.helloworld_jsp._jspService(org.apache.jsp.WEB_002dINF.jsp.helloworld_jsp:75)
| at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
| at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)
| at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)
| at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
| at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
| at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at
org.jboss.portal.portlet.impl.PortletRequestDispatcherImpl.execute(PortletRequestDispatcherImpl.java:71)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at
org.jboss.portal.server.servlet.CommandFilter.doFilter(CommandFilter.java:54)
| at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
| at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
| at
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:574)
| at
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
| at
org.jboss.portal.portlet.impl.PortletRequestDispatcherImpl.include(PortletRequestDispatcherImpl.java:113)
| at gontouf.helloworld.servlet.MonPortlet.doView(MonPortlet.java:19)
| at javax.portlet.GenericPortlet.doDispatch(GenericPortlet.java:235)
| at javax.portlet.GenericPortlet.render(GenericPortlet.java:163)
| at
org.jboss.portal.portlet.invocation.DispatcherInterceptor.invokeRequest(DispatcherInterceptor.java:163)
| at
org.jboss.portal.portlet.invocation.DispatcherInterceptor.invoke(DispatcherInterceptor.java:195)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.portlet.invocation.PreferencesInterceptor.invoke(PreferencesInterceptor.java:93)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.server.invocation.component.ContextDispatcherInterceptor$InvokeNextCommand.execute(ContextDispatcherInterceptor.java:94)
| at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
| at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
| at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
| at java.lang.reflect.Method.invoke(Method.java:585)
| at
org.jboss.portal.server.servlet.CommandServlet.doGet(CommandServlet.java:49)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
| at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
| at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
| at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:672)
| at
org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:539)
| at
org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:499)
| at
org.jboss.portal.server.invocation.component.ContextDispatcherInterceptor.invoke(ContextDispatcherInterceptor.java:58)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.core.invocation.AccessControlInterceptor.invoke(AccessControlInterceptor.java:125)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.server.invocation.component.CacheInterceptor.invoke(CacheInterceptor.java:74)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:238)
| at org.jboss.portal.server.Component.invoke(Component.java:173)
| at
org.jboss.portal.server.invocation.portal.MainDispatcherInterceptor.invoke(MainDispatcherInterceptor.java:93)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.core.invocation.StrategyInterceptor.invoke(StrategyInterceptor.java:184)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.core.invocation.ViewInterceptor.invoke(ViewInterceptor.java:118)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.server.invocation.portal.TargetInterceptor.invoke(TargetInterceptor.java:153)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.core.invocation.ContentTypeInterceptor.invoke(ContentTypeInterceptor.java:117)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.core.invocation.UserContextInterceptor.invoke(UserContextInterceptor.java:92)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:213)
| at
org.jboss.portal.server.impl.invocation.InvocationImpl.invokeNext(InvocationImpl.java:238)
| at org.jboss.portal.server.PortalServer.invoke(PortalServer.java:186)
| at
org.jboss.portal.server.servlet.AbstractMainServlet.invoke(AbstractMainServlet.java:78)
| at
org.jboss.portal.server.servlet.AbstractMainServlet.doGet(AbstractMainServlet.java:71)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
| at javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
Description of my xml files:
--hello-pages.xml:
<pages>
| <portal-name>default</portal-name>
| <page>
| <page-name>hello</page-name>
| <window>
| <window-name>HelloPortletWindow</window-name>
| <instance-ref>hello.HelloPortlet.HelloPortletInstance</instance-ref>
| <default>true</default>
| <region>left</region>
| <height>0</height>
| </window>
| </page>
| </pages>
|
--jboss-app.xml:
<jboss-app>
| <app-name>hello</app-name>
| </jboss-app>
--jboss-portlet.xml:
<portlet-app>
| <portlet>
| <portlet-name>HelloPortlet</portlet-name>
| <security></security>
| </portlet>
| </portlet-app>
--jboss-service.xml
--jboss-web.xml
--portlet-instances.xml:
<?xml version="1.0" standalone="yes"?>
| <instances>
| <instance>
| <instance-name>HelloPortletInstance</instance-name>
| <component-ref>HelloPortlet</component-ref>
| </instance>
| </instances>
--portlet.xml:
<?xml version="1.0" encoding="UTF-8"?>
| <portlet-app
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd"
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_1_0.xsd
/opt/SUNWps/dtd/portlet.xsd" version="1.0">
| <portlet>
| <portlet-name>HelloPortlet</portlet-name>
|
<portlet-class>gontouf.helloworld.servlet.MonPortlet</portlet-class>
| <init-param>
| <name>hellopage</name>
| <description>Start JSP page</description>
| <value>/WEB-INF/jsp/helloworld.jsp</value>
| </init-param>
| <supported-locale>en</supported-locale>
| <supports>
| <mime-type>text/html</mime-type>
| <portlet-mode>VIEW</portlet-mode>
| </supports>
| <portlet-info>
| <title>Mon port</title>
| </portlet-info>
| </portlet>
| </portlet-app>
|
--web.xml:
<?xml version="1.0" encoding="UTF-8"?>
| <!DOCTYPE web-app SYSTEM "http://java.sun.com/dtd/web-app_2_3.dtd">
| <web-app>
| <servlet>
| <servlet-name>Hello</servlet-name>
|
<servlet-class>gontouf.helloworld.servlet.HelloWorld</servlet-class>
| </servlet>
| <servlet-mapping>
| <servlet-name>Hello</servlet-name>
| <url-pattern>/helloworld</url-pattern>
| </servlet-mapping>
|
| </web-app>
I have another question:
the portlet call the jsp files, but when i test my couple servlet/jsp with the
URL http://localhost:8080/Helloworld-JSP/helloworld , i recover the value of
my variable "nom" and "monNom" but with the url
http://localhost:8080/Helloworld-JSP/helloworld.jsp, my variable take the
default value of the jsp page. That's logic, i know, but if the portlet include
the jsp files, i'm afraid that it'll be the same...
is it possible to call the servlet files instead of the jsp one???
I'm a little lost so if someone can put me back on the road of Portlet City :)
Thanks in advance.
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3884497#3884497
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3884497
-------------------------------------------------------
This SF.Net email is sponsored by the 'Do More With Dual!' webinar happening
July 14 at 8am PDT/11am EDT. We invite you to explore the latest in dual
core and dual graphics technology at this free one hour event hosted by HP,
AMD, and NVIDIA. To register visit http://www.hp.com/go/dualwebinar
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user