Jeff Sahol wrote:

> I'm working on a project using servlets and JSP. I need to have a way of
> referencing servlets from HTML links that is independent of the type of web
> server or servlet engine being used; we plan to distribute this to
> customers, who may be using any servlet/JSP engine. Right now I'm using JRun
> and IIS for development, and simply putting the servlets in the servlets/
> folder and referencing them by package name.servlet name. However, I'd like
> to see them integrated into the rest of the web site a little better, and
> ensure that I don't open new sessions navigating back and forth between
> servlets and JSP. The JSP is doing all the UI stuff, and forms in the pages
> have servlets as their actions.
>
> Problem is, every servlet engine has their own implementation of aliasing,
> so it would be a serious integration effort to install this product at the
> customer if we used servlet aliasing. Is there another way of getting
> servlets recognized as such, in a more standard-looking URL that looks like
> part of the application?
>
> Example:
> http://hostname/appname/foldername/login.jsp contains a form, with the
> following URL (a servlet) as its action:
> http://hostname/servlet/com.company.appname.LoginAction, and I'd prefer that
> this servlet be referenced as:
> http://hostname/appname/foldername/LoginServlet
>
> The one thing I considered is a JSP page for each servlet that simply
> forwards to the servlet, but surely there's a more elegant solution, right?
>
> (BTW we are trying to stay universal as possible so we are sticking to
> Servlet API 2.1 and JSP API 0.92.)
>

You are correct ... there is not much universality in how to deploy
applications with current version servlet/JSP servers.  This is one of the
major improvements you will see when servlet 2.2 + JSP 1.1 servers become
available.  Deployment information for a "web application" is standardized, so
you should be able to pretty much plop a specially formatted JAR file (called a
"web application archive") into any server, perhaps tweak a couple of
parameters in the deployment descriptor, and have it run.

In the mean time, about the best you can do is parameterize the URLs used in
your hyperlinks, instead of hard coding them.  For instance, instead of doing a
redirect to your login servlet like this:

    response.sendRedirect("/foldername/LoginServlet");

you might do something like this:

    String loginURL =
      getServletConfig().getInitParameter("login.url");
    response.sendRedirect(loginURL);

so that you can set the actual URLs in the initialization parameters of your
servlets.  If there are lots of them, it might be easier to use some sort of
common properties file that is shared by all the servlets and JSP pages.

>
> Thanks,
> Jeff
>

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to