You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-user@portals.apache.org by Irene Huang <ih...@acegain.com> on 2002/02/02 01:39:43 UTC

Q:Servlets and Database search in Jetspeed

Dear all,

If I have a JSP portlet, and I have a form:

    <form  method=get action="http://localhost:8080/examples/servlet/Dtest">

Q:
after click submit, i will go to the servlet page.
Is there a way i can display the result in the same page (without going to
the servlet page)?
Or what's the "exact link path" that I could add to the servlet page so that
user can click back to go to the starting page?

Q:
If I want to add a portlet for user to do database search, what is the
best/easist way to do it? any advice?



Thank you for help!!

Irene


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Q:Servlets and Database search in Jetspeed

Posted by David Sean Taylor <da...@bluesunrise.com>.
Right Ozgur, once again Ive misunderstand the question. Glad I don't work in
support, it would be a disaster.
So we are talking about including a servlet (or JSP)  from the same servlet
container.
In that case, ignore my response, thats for getting content outside of your
servlet container.

Take a look at the ServletInvokerPortlet


----- Original Message -----
From: "Ozgur Balsoy" <ba...@grids.ucs.indiana.edu>
To: "'Jetspeed Users List'" <je...@jakarta.apache.org>
Sent: Saturday, February 02, 2002 9:33 AM
Subject: RE: Q:Servlets and Database search in Jetspeed


> Actually, it is quite simple to keep the page within the portlet. Just
> put the Jetspeed's path to the action field of the form. However, this
> prevents you to link your form's action to another servlet. That is you
> have to print out your form with your servlet and you have to process
> the response with the very same servlet. I paste a small example to
> illustrate the idea and this works fine.
>
> The reason for this method is that Jetspeed is run by a central servlet
> which is called 'jetspeed' in jetspeed/WEB-INF/web.xml and mapped to the
> Java class org.apache.turbine.Turbine. This servlet retrieves the
> request and response objects, initializes a new similar object called
> rundata and and fills it with request, response, user profiler, etc and
> forwards it to all the portlets.
>
> When you set the action field to the main portal path, this Turbine
> servlet acts like a mother servlet and passes your request and response
> object to your child servlet.
>
> Ozgur
>
> --------------FormTest.java-----------------
> import javax.servlet.*;
> import javax.servlet.http.*;
> import java.io.*;
> import java.util.*;
>
> public class FormTest extends HttpServlet {
>     private static final String CONTENT_TYPE = "text/html";
>     //Process the HTTP Get request
>     public void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
>         response.setContentType(CONTENT_TYPE);
>         PrintWriter out = response.getWriter();
>
> String path = request.getContextPath() +
> request.getServletPath();
>
>         out.println("<html><head><title>FormTest</title></head><body>");
>
> if( request.getParameter("x_login") == null ) {
>     out.println("<form method=\"post\" action=\"" + path +
> "\">");
>     out.println("<p>Username:<input type=\"text\"
> name=\"x_username\" size=\"20\"><br>");
>     out.println("Password:<input type=\"password\"
> name=\"x_password\" size=\"20\"><br>");
>     out.println("<input type=\"submit\" name=\"x_login\"
> value=\"Login\"></p></form>");
> } else {
>     out.println("<p>You have logged in as ");
>     out.println( request.getParameter("x_username") );
>     out.println("<br>and your password is ");
>     out.println( request.getParameter("x_password") );
>
>     out.println("<a href=\"" + path + "\">Click here for the
> form</a>");
> }
>         out.println("</body></html>");
>
>     }
>     //Process the HTTP Post request
>     public void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
> doGet( request, response );
>     }
> }
>
> -----Original Message-----
> From: David Sean Taylor [mailto:david@bluesunrise.com]
> Sent: Saturday, February 02, 2002 12:27 AM
> To: Jetspeed Users List
> Subject: Re: Q:Servlets and Database search in Jetspeed
>
>
> ----- Original Message -----
> From: "Irene Huang" <ih...@acegain.com>
> To: "Jetspeed user" <je...@jakarta.apache.org>
> Sent: Friday, February 01, 2002 4:39 PM
> Subject: Q:Servlets and Database search in Jetspeed
>
>
> > Dear all,
> >
> > If I have a JSP portlet, and I have a form:
> >
> >     <form  method=get
> action="http://localhost:8080/examples/servlet/Dtest">
> >
> > Q:
> > after click submit, i will go to the servlet page.
> > Is there a way i can display the result in the same page (without
> going to
> > the servlet page)?
> > Or what's the "exact link path" that I could add to the servlet page
> so
> that
> > user can click back to go to the starting page?
> >
>
> Im not sure if I understand the question, but I think you are trying to
> always keep the servlet in the portlet window as you navigate thru the
> servlet.
>
> If so, you may need to somehow track the state of your session between
> your
> portlet and the servlet it is 'hosting'.
> One simple way is to write the state into a query param or directly into
> the
> HTML(into an INPUT)
> A more complex way would be to completely proxy the whole session....
> Also, you will also need to rewrite your links (something like in the
> WebPagePortlet, but you want to rewrite back to Jetspeed)
>
> > Q:
> > If I want to add a portlet for user to do database search, what is the
> > best/easist way to do it? any advice?
> >
>
> You can use whatever you like to access the database in Java (JDBC comes
> to
> mind...), callout to any methods.
> Don't recommend putting db code in the portlet, abstract it out, layer
> your
> data access.
> Take a look at Torque
> http://jakarta.apache.org/turbine/torque/index.html
>
> >
> >
> > Thank you for help!!
> >
> > Irene
> >
> >
> > --
> > To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> > For additional commands, e-mail:
> <ma...@jakarta.apache.org>
> >
> >
>
>
>
> --
> To unsubscribe, e-mail:
> <ma...@jakarta.apache.org>
> For additional commands, e-mail:
> <ma...@jakarta.apache.org>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: new ServletInvokerPortlet

Posted by Ozgur Balsoy <ba...@grids.ucs.indiana.edu>.
David,

I don't know if I have missed something. I have assumed that when we add
a ServletInvokerPortlet entry into the registry and add it into the
layout, then everything runs with servlets, hence all the output comes
from out.println()s. If I have JSP or Velocity, then it no longer
becomes a servlet portlet, right?

If I have the following velocity template as a velocity portlet,

<form action="${jlink}/servlets/foobar" method="post">
Name: <input name="text" size="30" /><br/>
Email:<input name="text" size="30" /><br/>
<input type="submit" value="Submit" />
</form>

and click on submit, then the servlet portlet wouldn't replace this
velocity macro. It would only work if the servlet portlet is on the same
page with this velocity portlet.

I think only thing servlet developers must pay attention is how to
construct a servlet link which I believe should be like:

String jlink = request.getContextPath() + request.getServletPath();  
String servlet = "/foo/bar";
String fullpath = jlink + "/servlets" + servlet;

out.println("<a href=\"" + fullpath + "\">another servlet</a>");

This must work for all the Jetspeed installations.

Ozgur

-----Original Message-----
From: David Sean Taylor [mailto:david@bluesunrise.com] 
Sent: Saturday, February 02, 2002 2:58 PM
To: Jetspeed Users List
Subject: Re: new ServletInvokerPortlet

> Maybe this would be a compromise right now. I think this is better
than
> the old ServletInvokerPortlet.

yes, ok. Lets see if anyone else wants to comment.
If no one objects then I'll merge the patch

Could you provide me an example using velocity or jsp (instead of
out.println)?
I will include it in the tutorial

Thanks,

David



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: new ServletInvokerPortlet

Posted by David Sean Taylor <da...@bluesunrise.com>.
 Im a little unclear how a JSPPortlet is different from a ServletInvoker
calling a JSP. Differences I can see is that with the JSPPortlet, we will
automatically search for the JSP based on Jetspeed's fallback algorithm
(thats nice), add the default objects, and we use the Turbine service to
invoke it. With the ServletInvoker, we simply get a dispatcher and include
the JSP.

It seems like there a lot of overhead (invoking other servlets) with
aggregating JSPs, compared to Turbine/Velocity's approach of working within
the same servlet (Turbine).

 I've also noticed that when I run the JSP-based templating, it runs a lot
slower than Velocity (perceptually). I believe there are metrics in the code
somewhere to measure this...

Here are some of the possible examples of invoking other servlets, although
JSP always seems to get invoked via the request dispatcher include
mechanism:

- a plain old servlet (which you have already provided)
- a Velocity Servlet
http://jakarta.apache.org/velocity/developer-guide.html#Using%20Velocity%20I
n%20Servlets
- another Turbine servlet
- a JSP (we could also illustrate Struts or  Jakarta Taglibs)

Thanks for the examples!
 I will include them in the Jetspeed Tutorial,

David


----- Original Message -----
From: "Ozgur Balsoy" <ba...@grids.ucs.indiana.edu>
To: "'Jetspeed Users List'" <je...@jakarta.apache.org>
Sent: Saturday, February 02, 2002 2:32 PM
Subject: tRE: new ServletInvokerPortlet


> > Could you provide me an example using velocity or jsp (instead of
> out.println)? I will include it in the tutorial
>
> I have noticed that this is what you were looking for. This JSP is very
> similar to hello.vm which is already in the Jetspeed package.
>
> Ozgur
>
> <%@ taglib uri='/WEB-INF/templates/jsp/tld/template.tld'
> prefix='jetspeed' %>
> <%@ page import="org.apache.jetspeed.util.URILookup" %>
>
> <%
>     if( request.getParameter("x_login") == null ) { %>
>
> <form method="get" action="<jetspeed:uriLookup type="Home" />">
> <p> Username:<input type="text" name="x_username" size="20"><br>
>     Password:<input type="password" name="x_password"
> size="20"><br>
>     <input type="submit" name="x_login" value="Login">
> </p>
> </form>
>
>     <% } else { %>
>
> <p> You have logged in as <%=
> request.getParameter("x_username")%><br>
>     and your password is <%=
> request.getParameter("x_password")%>
> </p>
> <p> <a href="<jetspeed:uriLookup type="Home" />">
> Click here for the form</a>
> </p>
>     <% } %>
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: new ServletInvokerPortlet

Posted by Ozgur Balsoy <ba...@grids.ucs.indiana.edu>.
> Could you provide me an example using velocity or jsp (instead of
out.println)? I will include it in the tutorial

I have noticed that this is what you were looking for. This JSP is very
similar to hello.vm which is already in the Jetspeed package.

Ozgur

<%@ taglib uri='/WEB-INF/templates/jsp/tld/template.tld' 
	prefix='jetspeed' %>
<%@ page import="org.apache.jetspeed.util.URILookup" %>

<%
    if( request.getParameter("x_login") == null ) { %>

	<form method="get" action="<jetspeed:uriLookup type="Home" />">
	<p> Username:<input type="text" name="x_username" size="20"><br>
	    Password:<input type="password" name="x_password"
size="20"><br>
	    <input type="submit" name="x_login" value="Login">
	</p>
	</form>

    <% } else { %>

	<p> You have logged in as <%=
request.getParameter("x_username")%><br>
	    and your password is <%=
request.getParameter("x_password")%>
	</p>
	<p> <a href="<jetspeed:uriLookup type="Home" />">
		Click here for the form</a>
	</p>
    <% } %>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: new ServletInvokerPortlet

Posted by Ozgur Balsoy <ba...@grids.ucs.indiana.edu>.
I have attached some examples to illustrate the new
ServletInvokerPortlet usage with navigation. You might find them useful
once you have the patch done.

These servlets work fine outside the portal, i.e. /jetspeed/servlet1. 

Thanks for your support, David.

Ozgur

-----Original Message-----
From: David Sean Taylor [mailto:david@bluesunrise.com] 
Sent: Saturday, February 02, 2002 2:58 PM
To: Jetspeed Users List
Subject: Re: new ServletInvokerPortlet

> Maybe this would be a compromise right now. I think this is better
than
> the old ServletInvokerPortlet.

yes, ok. Lets see if anyone else wants to comment.
If no one objects then I'll merge the patch

Could you provide me an example using velocity or jsp (instead of
out.println)?
I will include it in the tutorial

Thanks,

David



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>


Re: new ServletInvokerPortlet

Posted by David Sean Taylor <da...@bluesunrise.com>.
> Maybe this would be a compromise right now. I think this is better than
> the old ServletInvokerPortlet.

yes, ok. Lets see if anyone else wants to comment.
If no one objects then I'll merge the patch

Could you provide me an example using velocity or jsp (instead of
out.println)?
I will include it in the tutorial

Thanks,

David



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: new ServletInvokerPortlet

Posted by Ozgur Balsoy <ba...@grids.ucs.indiana.edu>.
The top-level servlet is the first servlet you want to start with. This
might construct a menu or a form within the portlet. Basically, it is
the servlet that Jetspeed runs now. I just call it top-level because it
is kind of the top of the navigation.

No, it is not Jetspeed. It is the servlet portlet which is defined in
the portlet registry.

Yes, you are right on losing the portability. Maybe this might be solved
by additional changes like altering request object so that .getXXX()
methods would return right values. We can never prevent people, of
course, from hard coding paths, parameters, etc.

Maybe this would be a compromise right now. I think this is better than
the old ServletInvokerPortlet.

Ozgur

-----Original Message-----
From: David Sean Taylor [mailto:david@bluesunrise.com] 
Sent: Saturday, February 02, 2002 2:30 PM
To: Jetspeed Users List
Subject: Re: new ServletInvokerPortlet

I think I see how it works. So you are trying to define a way to
navigate
between different servlets, and keep the servlets within a portal
window?

Not sure if I understand this "top-level" concept?
Are you saying that is Jetspeed?
If so, isnt it better to do something like $link and get it dynamically

I guess the problem I have with this is that it assumes that all
servlets
will have to know about the fact that they are working within a portal,
which normally is not the case


----- Original Message -----
From: "Ozgur Balsoy" <ba...@grids.ucs.indiana.edu>
To: "'Jetspeed Users List'" <je...@jakarta.apache.org>
Sent: Saturday, February 02, 2002 10:54 AM
Subject: new ServletInvokerPortlet


> I propose the following changes to ServletInvokerPortlet to allow
> servlet navigation.
>
> * Servlet's portlet registry will point the top level servlet defined
by
> <parameter name="url" value="/toplevel-servlet" />
>   This servlet will construct the first page. This is what Jetspeed
has
> now. So I see no changes here.
>
> * New servlets will be linked and run without registry entries with an
> addition to the portal URI such as
> "/jetspeed/portal/servlets/servletname"
>
> * Any path right after the servlets command, "/servlets",  will be
given
> to ServletInvokerPortlet as the new URI which must be mapped to a
> servlet in web.xml. The servlets command is NOT a part of this mapping
> or path. Any preceding "/servlet" or "/servlets" paths included in the
> servlet mapping must be repeated here i.e.
> /jetspeed/portal/servlets/servlet/myservlet
>
>   This assumes that the servlets command will not precede any other
> portal parameter, i.e. /actions, /pane, /user, /group. This should
work
> for the servlet 'bar' as:
>    /jetspeed/portal/page/intro/pane0/Foo/servlets/bar
>
> * If there is no servlets command in the URI, the servlet invoker will
> attempt to dispatch the top-level servlet from the registry as
> previously explained.
>
> The new ServletInvokerPortlet changes are the following to provide all
> of these proposals.
>
> cvs diff ServletInvokerPortlet.java (in directory
>
C:\ozgur\jakarta-jetspeed\src\java\org\apache\jetspeed\portal\portlets\)
> Index: ServletInvokerPortlet.java
> ===================================================================
> RCS file:
>
/home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/por
> tlets/ServletInvokerPortlet.java,v
> retrieving revision 1.1
> diff -r1.1 ServletInvokerPortlet.java
> 90c90,97
> <   servletURL = (String)
> this.getPortletConfig().getInitParameter("url");
> ---
> >   String pathInfo = rundata.getRequest().getPathInfo();
> >   int pos;
> >   if(pathInfo != null &&
> >     (pos = pathInfo.indexOf("/servlets")) >=0 ) {
> >       servletURL = pathInfo.substring(pos +
> "/servlets".length());
> >   }
> >   if(servletURL == null)
> >     servletURL = (String)
> this.getPortletConfig().getInitParameter("url");
>
>
> Finally, this is how a servlet would link to another:
>
>     public void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
>         response.setContentType(CONTENT_TYPE);
>         PrintWriter out = response.getWriter();
>
> String path = request.getContextPath() +
> request.getServletPath();
> String nextServlet = "/snoop";
> String newPath = path + "/servlets" + nextServlet;
>
>
out.println("<html><head><title>FormTest</title></head><body>");
>
> if( request.getParameter("x_login") == null ) {
>     out.println("<form method=\"get\" action=\"" + newPath +
> "\">");
>     out.println("<p>Username:<input type=\"text\"
> name=\"x_username\" size=\"20\"><br>");
>     out.println("Password:<input type=\"password\"
> name=\"x_password\" size=\"20\"><br>");
>     out.println("<input type=\"submit\" name=\"x_login\"
> value=\"Login\"></p></form>");
> }
>         out.println("</body></html>");
>
>     }
>
> I hope this message hasn't become too long and messy. Any comments and
> ideas? This also might be handled the way actions are handled, I
guess.
>
> Ozgur
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: new ServletInvokerPortlet

Posted by David Sean Taylor <da...@bluesunrise.com>.
I think I see how it works. So you are trying to define a way to navigate
between different servlets, and keep the servlets within a portal window?

Not sure if I understand this "top-level" concept?
Are you saying that is Jetspeed?
If so, isnt it better to do something like $link and get it dynamically

I guess the problem I have with this is that it assumes that all servlets
will have to know about the fact that they are working within a portal,
which normally is not the case


----- Original Message -----
From: "Ozgur Balsoy" <ba...@grids.ucs.indiana.edu>
To: "'Jetspeed Users List'" <je...@jakarta.apache.org>
Sent: Saturday, February 02, 2002 10:54 AM
Subject: new ServletInvokerPortlet


> I propose the following changes to ServletInvokerPortlet to allow
> servlet navigation.
>
> * Servlet's portlet registry will point the top level servlet defined by
> <parameter name="url" value="/toplevel-servlet" />
>   This servlet will construct the first page. This is what Jetspeed has
> now. So I see no changes here.
>
> * New servlets will be linked and run without registry entries with an
> addition to the portal URI such as
> "/jetspeed/portal/servlets/servletname"
>
> * Any path right after the servlets command, "/servlets",  will be given
> to ServletInvokerPortlet as the new URI which must be mapped to a
> servlet in web.xml. The servlets command is NOT a part of this mapping
> or path. Any preceding "/servlet" or "/servlets" paths included in the
> servlet mapping must be repeated here i.e.
> /jetspeed/portal/servlets/servlet/myservlet
>
>   This assumes that the servlets command will not precede any other
> portal parameter, i.e. /actions, /pane, /user, /group. This should work
> for the servlet 'bar' as:
>    /jetspeed/portal/page/intro/pane0/Foo/servlets/bar
>
> * If there is no servlets command in the URI, the servlet invoker will
> attempt to dispatch the top-level servlet from the registry as
> previously explained.
>
> The new ServletInvokerPortlet changes are the following to provide all
> of these proposals.
>
> cvs diff ServletInvokerPortlet.java (in directory
> C:\ozgur\jakarta-jetspeed\src\java\org\apache\jetspeed\portal\portlets\)
> Index: ServletInvokerPortlet.java
> ===================================================================
> RCS file:
> /home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/por
> tlets/ServletInvokerPortlet.java,v
> retrieving revision 1.1
> diff -r1.1 ServletInvokerPortlet.java
> 90c90,97
> <   servletURL = (String)
> this.getPortletConfig().getInitParameter("url");
> ---
> >   String pathInfo = rundata.getRequest().getPathInfo();
> >   int pos;
> >   if(pathInfo != null &&
> >     (pos = pathInfo.indexOf("/servlets")) >=0 ) {
> >       servletURL = pathInfo.substring(pos +
> "/servlets".length());
> >   }
> >   if(servletURL == null)
> >     servletURL = (String)
> this.getPortletConfig().getInitParameter("url");
>
>
> Finally, this is how a servlet would link to another:
>
>     public void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
>         response.setContentType(CONTENT_TYPE);
>         PrintWriter out = response.getWriter();
>
> String path = request.getContextPath() +
> request.getServletPath();
> String nextServlet = "/snoop";
> String newPath = path + "/servlets" + nextServlet;
>
>         out.println("<html><head><title>FormTest</title></head><body>");
>
> if( request.getParameter("x_login") == null ) {
>     out.println("<form method=\"get\" action=\"" + newPath +
> "\">");
>     out.println("<p>Username:<input type=\"text\"
> name=\"x_username\" size=\"20\"><br>");
>     out.println("Password:<input type=\"password\"
> name=\"x_password\" size=\"20\"><br>");
>     out.println("<input type=\"submit\" name=\"x_login\"
> value=\"Login\"></p></form>");
> }
>         out.println("</body></html>");
>
>     }
>
> I hope this message hasn't become too long and messy. Any comments and
> ideas? This also might be handled the way actions are handled, I guess.
>
> Ozgur
>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


new ServletInvokerPortlet

Posted by Ozgur Balsoy <ba...@grids.ucs.indiana.edu>.
I propose the following changes to ServletInvokerPortlet to allow
servlet navigation.

* Servlet's portlet registry will point the top level servlet defined by
<parameter name="url" value="/toplevel-servlet" /> 
  This servlet will construct the first page. This is what Jetspeed has
now. So I see no changes here.

* New servlets will be linked and run without registry entries with an
addition to the portal URI such as
"/jetspeed/portal/servlets/servletname"

* Any path right after the servlets command, "/servlets",  will be given
to ServletInvokerPortlet as the new URI which must be mapped to a
servlet in web.xml. The servlets command is NOT a part of this mapping
or path. Any preceding "/servlet" or "/servlets" paths included in the
servlet mapping must be repeated here i.e.
/jetspeed/portal/servlets/servlet/myservlet

  This assumes that the servlets command will not precede any other
portal parameter, i.e. /actions, /pane, /user, /group. This should work
for the servlet 'bar' as:
   /jetspeed/portal/page/intro/pane0/Foo/servlets/bar

* If there is no servlets command in the URI, the servlet invoker will
attempt to dispatch the top-level servlet from the registry as
previously explained.

The new ServletInvokerPortlet changes are the following to provide all
of these proposals.

cvs diff ServletInvokerPortlet.java (in directory
C:\ozgur\jakarta-jetspeed\src\java\org\apache\jetspeed\portal\portlets\)
Index: ServletInvokerPortlet.java
===================================================================
RCS file:
/home/cvspublic/jakarta-jetspeed/src/java/org/apache/jetspeed/portal/por
tlets/ServletInvokerPortlet.java,v
retrieving revision 1.1
diff -r1.1 ServletInvokerPortlet.java
90c90,97
< 	  servletURL = (String)
this.getPortletConfig().getInitParameter("url");
---
> 	  String pathInfo = rundata.getRequest().getPathInfo();
> 	  int pos;
> 	  if(pathInfo != null &&
> 	    (pos = pathInfo.indexOf("/servlets")) >=0 ) {
> 	      servletURL = pathInfo.substring(pos +
"/servlets".length());
> 	  }
> 	  if(servletURL == null)
> 	    servletURL = (String)
this.getPortletConfig().getInitParameter("url");


Finally, this is how a servlet would link to another:

    public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();

	String path = request.getContextPath() +
request.getServletPath();
	String nextServlet = "/snoop";
	String newPath = path + "/servlets" + nextServlet;

        out.println("<html><head><title>FormTest</title></head><body>");

	if( request.getParameter("x_login") == null ) {
	    out.println("<form method=\"get\" action=\"" + newPath +
"\">");
	    out.println("<p>Username:<input type=\"text\"
name=\"x_username\" size=\"20\"><br>");
	    out.println("Password:<input type=\"password\"
name=\"x_password\" size=\"20\"><br>");
	    out.println("<input type=\"submit\" name=\"x_login\"
value=\"Login\"></p></form>");
	}
        out.println("</body></html>");

    }

I hope this message hasn't become too long and messy. Any comments and
ideas? This also might be handled the way actions are handled, I guess.

Ozgur




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Attn: Ozgur RE:Q:Servlets and Database search in Jetspeed

Posted by Irene Huang <ih...@acegain.com>.
Ozgur,

I've followed your instructions, after I click "add" portlet, the
"FormTestDemo" appeared in the customize pane.
After I click "Save&Apply", all the portlets still there but the
"FormTestDemo" didn't show up.
any idea?

thank you for quick reply :)

Irene


-----Original Message-----
From: Ozgur Balsoy [mailto:balsoy@grids.ucs.indiana.edu]
Sent: Monday, February 04, 2002 5:05 PM
To: 'Jetspeed Users List'
Subject: RE: Attn: Ozgur RE:Q:Servlets and Database search in Jetspeed


Irene,

1) The portlet entry for my test servlet should be similar to this:

<portlet-entry name="Servlet" hidden="false" type="abstract"
application="false">
<classname>org.apache.jetspeed.portal.portlets.ServletInvokerPortlet
   </classname>
</portlet-entry>
<portlet-entry name="FormTestServlet" hidden="false" type="ref"
        parent="Servlet" application="false">
        <meta-info>
            <title>FormTest Demo</title>
            <description>FormTest Demo</description>
        </meta-info>
        <parameter name="url" value="/formtest" hidden="false"/>
        <media-type ref="html"/>
    </portlet-entry>

2) Add these entries to your jetspeed\WEB-INF\web.xml file:

    <servlet>
	<servlet-name>
		formtest
	</servlet-name>
	<servlet-class>
		FormTest
	</servlet-class>
    </servlet>

    <servlet-mapping>
	<servlet-name>
		formtest
	</servlet-name>
	<url-pattern>
		/formtest
	</url-pattern>
    </servlet-mapping>

3) Put FormTest.class file into WEB-INF\classes if you have no package
name for it. If you have a package name, it must be put properly, and
the servlet entry in web.xml must reflect that.

4) Restart Tomcat.

Let me know if these fail.

Ozgur

-----Original Message-----
From: Irene Huang [mailto:ihuang@acegain.com]
Sent: Monday, February 04, 2002 3:14 PM
To: Jetspeed Users List
Subject: Attn: Ozgur RE:Q:Servlets and Database search in Jetspeed

Ozgur,

I've tried the attached servlet sample you post, but I still couldn't
run it
as a portlet.
my steps:

1. add this into one of my .xreg:
    <portlet-entry name="Servlet Testing ..." hidden="false"
        type="instance" application="false">
        <meta-info>
            <description>Servlet Testing again</description>
        </meta-info>
        <classname>com.bluesunrise.portal.portlets.FormTest</classname>
        <media-type ref="html"/>
    </portlet-entry>

2. put the class file of this servlet in
<jetspeed-home>\WEB-INF\classes\com\bluesunrise\portal\portlets
3. Start Tomcat, Log in, and try to add portlet

but when I try to add this servlet after I click "save & apply", the
portlets all disappear.
Can you tell me the steps to make this servlet running as a Jetspeed
portlet?
Where should I put the class file of this servlet at?
Do I need to modify this web.xml file? //jetspeed/WEB-INF/web.xml


Thank you for help!!

Irene




--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Attn: Ozgur RE:Q:Servlets and Database search in Jetspeed

Posted by Ozgur Balsoy <ba...@grids.ucs.indiana.edu>.
Irene,

1) The portlet entry for my test servlet should be similar to this:

<portlet-entry name="Servlet" hidden="false" type="abstract"
application="false">
<classname>org.apache.jetspeed.portal.portlets.ServletInvokerPortlet
   </classname>
</portlet-entry>
<portlet-entry name="FormTestServlet" hidden="false" type="ref"
        parent="Servlet" application="false">
        <meta-info>
            <title>FormTest Demo</title>
            <description>FormTest Demo</description>
        </meta-info>
        <parameter name="url" value="/formtest" hidden="false"/>
        <media-type ref="html"/>
    </portlet-entry>

2) Add these entries to your jetspeed\WEB-INF\web.xml file:

    <servlet>
	<servlet-name>
		formtest
	</servlet-name>
	<servlet-class>
		FormTest
	</servlet-class>
    </servlet>

    <servlet-mapping>
	<servlet-name>
		formtest
	</servlet-name>
	<url-pattern>
		/formtest
	</url-pattern>
    </servlet-mapping>

3) Put FormTest.class file into WEB-INF\classes if you have no package
name for it. If you have a package name, it must be put properly, and
the servlet entry in web.xml must reflect that.

4) Restart Tomcat.

Let me know if these fail.

Ozgur

-----Original Message-----
From: Irene Huang [mailto:ihuang@acegain.com] 
Sent: Monday, February 04, 2002 3:14 PM
To: Jetspeed Users List
Subject: Attn: Ozgur RE:Q:Servlets and Database search in Jetspeed

Ozgur,

I've tried the attached servlet sample you post, but I still couldn't
run it
as a portlet.
my steps:

1. add this into one of my .xreg:
    <portlet-entry name="Servlet Testing ..." hidden="false"
        type="instance" application="false">
        <meta-info>
            <description>Servlet Testing again</description>
        </meta-info>
        <classname>com.bluesunrise.portal.portlets.FormTest</classname>
        <media-type ref="html"/>
    </portlet-entry>

2. put the class file of this servlet in
<jetspeed-home>\WEB-INF\classes\com\bluesunrise\portal\portlets
3. Start Tomcat, Log in, and try to add portlet

but when I try to add this servlet after I click "save & apply", the
portlets all disappear.
Can you tell me the steps to make this servlet running as a Jetspeed
portlet?
Where should I put the class file of this servlet at?
Do I need to modify this web.xml file? //jetspeed/WEB-INF/web.xml


Thank you for help!!

Irene




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Attn: Ozgur RE:Q:Servlets and Database search in Jetspeed

Posted by Irene Huang <ih...@acegain.com>.
Ozgur,

I've tried the attached servlet sample you post, but I still couldn't run it
as a portlet.
my steps:

1. add this into one of my .xreg:
    <portlet-entry name="Servlet Testing ..." hidden="false"
        type="instance" application="false">
        <meta-info>
            <description>Servlet Testing again</description>
        </meta-info>
        <classname>com.bluesunrise.portal.portlets.FormTest</classname>
        <media-type ref="html"/>
    </portlet-entry>

2. put the class file of this servlet in
<jetspeed-home>\WEB-INF\classes\com\bluesunrise\portal\portlets
3. Start Tomcat, Log in, and try to add portlet

but when I try to add this servlet after I click "save & apply", the
portlets all disappear.
Can you tell me the steps to make this servlet running as a Jetspeed
portlet?
Where should I put the class file of this servlet at?
Do I need to modify this web.xml file? //jetspeed/WEB-INF/web.xml


Thank you for help!!

Irene

-----Original Message-----
From: Ozgur Balsoy [mailto:balsoy@grids.ucs.indiana.edu]
Sent: Saturday, February 02, 2002 9:34 AM
To: 'Jetspeed Users List'
Subject: RE: Q:Servlets and Database search in Jetspeed


Actually, it is quite simple to keep the page within the portlet. Just
put the Jetspeed's path to the action field of the form. However, this
prevents you to link your form's action to another servlet. That is you
have to print out your form with your servlet and you have to process
the response with the very same servlet. I paste a small example to
illustrate the idea and this works fine.

The reason for this method is that Jetspeed is run by a central servlet
which is called 'jetspeed' in jetspeed/WEB-INF/web.xml and mapped to the
Java class org.apache.turbine.Turbine. This servlet retrieves the
request and response objects, initializes a new similar object called
rundata and and fills it with request, response, user profiler, etc and
forwards it to all the portlets.

When you set the action field to the main portal path, this Turbine
servlet acts like a mother servlet and passes your request and response
object to your child servlet.

Ozgur

--------------FormTest.java-----------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class FormTest extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html";
    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();

	String path = request.getContextPath() +
request.getServletPath();

        out.println("<html><head><title>FormTest</title></head><body>");

	if( request.getParameter("x_login") == null ) {
	    out.println("<form method=\"post\" action=\"" + path +
"\">");
	    out.println("<p>Username:<input type=\"text\"
name=\"x_username\" size=\"20\"><br>");
	    out.println("Password:<input type=\"password\"
name=\"x_password\" size=\"20\"><br>");
	    out.println("<input type=\"submit\" name=\"x_login\"
value=\"Login\"></p></form>");
	} else {
	    out.println("<p>You have logged in as ");
	    out.println( request.getParameter("x_username") );
	    out.println("<br>and your password is ");
	    out.println( request.getParameter("x_password") );

	    out.println("<a href=\"" + path + "\">Click here for the
form</a>");
	}
        out.println("</body></html>");

    }
    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
	doGet( request, response );
    }
}

-----Original Message-----
From: David Sean Taylor [mailto:david@bluesunrise.com]
Sent: Saturday, February 02, 2002 12:27 AM
To: Jetspeed Users List
Subject: Re: Q:Servlets and Database search in Jetspeed


----- Original Message -----
From: "Irene Huang" <ih...@acegain.com>
To: "Jetspeed user" <je...@jakarta.apache.org>
Sent: Friday, February 01, 2002 4:39 PM
Subject: Q:Servlets and Database search in Jetspeed


> Dear all,
>
> If I have a JSP portlet, and I have a form:
>
>     <form  method=get
action="http://localhost:8080/examples/servlet/Dtest">
>
> Q:
> after click submit, i will go to the servlet page.
> Is there a way i can display the result in the same page (without
going to
> the servlet page)?
> Or what's the "exact link path" that I could add to the servlet page
so
that
> user can click back to go to the starting page?
>

Im not sure if I understand the question, but I think you are trying to
always keep the servlet in the portlet window as you navigate thru the
servlet.

If so, you may need to somehow track the state of your session between
your
portlet and the servlet it is 'hosting'.
One simple way is to write the state into a query param or directly into
the
HTML(into an INPUT)
A more complex way would be to completely proxy the whole session....
Also, you will also need to rewrite your links (something like in the
WebPagePortlet, but you want to rewrite back to Jetspeed)

> Q:
> If I want to add a portlet for user to do database search, what is the
> best/easist way to do it? any advice?
>

You can use whatever you like to access the database in Java (JDBC comes
to
mind...), callout to any methods.
Don't recommend putting db code in the portlet, abstract it out, layer
your
data access.
Take a look at Torque
http://jakarta.apache.org/turbine/torque/index.html

>
>
> Thank you for help!!
>
> Irene
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Q:Servlets and Database search in Jetspeed

Posted by Ozgur Balsoy <ba...@grids.ucs.indiana.edu>.
Actually, it is quite simple to keep the page within the portlet. Just
put the Jetspeed's path to the action field of the form. However, this
prevents you to link your form's action to another servlet. That is you
have to print out your form with your servlet and you have to process
the response with the very same servlet. I paste a small example to
illustrate the idea and this works fine.

The reason for this method is that Jetspeed is run by a central servlet
which is called 'jetspeed' in jetspeed/WEB-INF/web.xml and mapped to the
Java class org.apache.turbine.Turbine. This servlet retrieves the
request and response objects, initializes a new similar object called
rundata and and fills it with request, response, user profiler, etc and
forwards it to all the portlets.

When you set the action field to the main portal path, this Turbine
servlet acts like a mother servlet and passes your request and response
object to your child servlet.

Ozgur

--------------FormTest.java-----------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public class FormTest extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html";
    //Process the HTTP Get request
    public void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();

	String path = request.getContextPath() +
request.getServletPath();

        out.println("<html><head><title>FormTest</title></head><body>");

	if( request.getParameter("x_login") == null ) {
	    out.println("<form method=\"post\" action=\"" + path +
"\">");
	    out.println("<p>Username:<input type=\"text\"
name=\"x_username\" size=\"20\"><br>");
	    out.println("Password:<input type=\"password\"
name=\"x_password\" size=\"20\"><br>");
	    out.println("<input type=\"submit\" name=\"x_login\"
value=\"Login\"></p></form>");
	} else {
	    out.println("<p>You have logged in as ");
	    out.println( request.getParameter("x_username") );
	    out.println("<br>and your password is ");
	    out.println( request.getParameter("x_password") );

	    out.println("<a href=\"" + path + "\">Click here for the
form</a>");
	}
        out.println("</body></html>");

    }
    //Process the HTTP Post request
    public void doPost(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
	doGet( request, response );
    }
}

-----Original Message-----
From: David Sean Taylor [mailto:david@bluesunrise.com] 
Sent: Saturday, February 02, 2002 12:27 AM
To: Jetspeed Users List
Subject: Re: Q:Servlets and Database search in Jetspeed


----- Original Message -----
From: "Irene Huang" <ih...@acegain.com>
To: "Jetspeed user" <je...@jakarta.apache.org>
Sent: Friday, February 01, 2002 4:39 PM
Subject: Q:Servlets and Database search in Jetspeed


> Dear all,
>
> If I have a JSP portlet, and I have a form:
>
>     <form  method=get
action="http://localhost:8080/examples/servlet/Dtest">
>
> Q:
> after click submit, i will go to the servlet page.
> Is there a way i can display the result in the same page (without
going to
> the servlet page)?
> Or what's the "exact link path" that I could add to the servlet page
so
that
> user can click back to go to the starting page?
>

Im not sure if I understand the question, but I think you are trying to
always keep the servlet in the portlet window as you navigate thru the
servlet.

If so, you may need to somehow track the state of your session between
your
portlet and the servlet it is 'hosting'.
One simple way is to write the state into a query param or directly into
the
HTML(into an INPUT)
A more complex way would be to completely proxy the whole session....
Also, you will also need to rewrite your links (something like in the
WebPagePortlet, but you want to rewrite back to Jetspeed)

> Q:
> If I want to add a portlet for user to do database search, what is the
> best/easist way to do it? any advice?
>

You can use whatever you like to access the database in Java (JDBC comes
to
mind...), callout to any methods.
Don't recommend putting db code in the portlet, abstract it out, layer
your
data access.
Take a look at Torque
http://jakarta.apache.org/turbine/torque/index.html

>
>
> Thank you for help!!
>
> Irene
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
For additional commands, e-mail:
<ma...@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Q:Servlets and Database search in Jetspeed

Posted by David Sean Taylor <da...@bluesunrise.com>.
----- Original Message -----
From: "Irene Huang" <ih...@acegain.com>
To: "Jetspeed user" <je...@jakarta.apache.org>
Sent: Friday, February 01, 2002 4:39 PM
Subject: Q:Servlets and Database search in Jetspeed


> Dear all,
>
> If I have a JSP portlet, and I have a form:
>
>     <form  method=get
action="http://localhost:8080/examples/servlet/Dtest">
>
> Q:
> after click submit, i will go to the servlet page.
> Is there a way i can display the result in the same page (without going to
> the servlet page)?
> Or what's the "exact link path" that I could add to the servlet page so
that
> user can click back to go to the starting page?
>

Im not sure if I understand the question, but I think you are trying to
always keep the servlet in the portlet window as you navigate thru the
servlet.

If so, you may need to somehow track the state of your session between your
portlet and the servlet it is 'hosting'.
One simple way is to write the state into a query param or directly into the
HTML(into an INPUT)
A more complex way would be to completely proxy the whole session....
Also, you will also need to rewrite your links (something like in the
WebPagePortlet, but you want to rewrite back to Jetspeed)

> Q:
> If I want to add a portlet for user to do database search, what is the
> best/easist way to do it? any advice?
>

You can use whatever you like to access the database in Java (JDBC comes to
mind...), callout to any methods.
Don't recommend putting db code in the portlet, abstract it out, layer your
data access.
Take a look at Torque http://jakarta.apache.org/turbine/torque/index.html

>
>
> Thank you for help!!
>
> Irene
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>