jsp mapping

Discussion in 'Java' started by homecurr@yahoo.com, Apr 21, 2004.

  1. Guest

    I am using tomcat. In the web.xml for a webapp, I can do servlet mapping like

    <servlet-mapping>
    <servlet-name>myServlet</servlet-name>
    <url-pattern>/m</url-pattern>
    </servlet-mapping>

    Can I map a jsp?

    Thanks,

    John
     
    , Apr 21, 2004
    #1
    1. Advertising

  2. kd Guest

    Not the way your thinking of. But maybe the ff will help.

    You can map a welcome page, ie www.mycompany.com maps to
    www.mycompany.com/helloppl.jsp

    Otherwise one accesses JSP's directly, for instance,
    localhost/mywebapp/jspfolder/Hello.jsp

    wrote:
    > I am using tomcat. In the web.xml for a webapp, I can do servlet mapping like
    >
    > <servlet-mapping>
    > <servlet-name>myServlet</servlet-name>
    > <url-pattern>/m</url-pattern>
    > </servlet-mapping>
    >
    > Can I map a jsp?
    >
    > Thanks,
    >
    > John
     
    kd, Apr 21, 2004
    #2
    1. Advertising

  3. Chris Smith Guest

    kd wrote:
    > Not the way your thinking of. But maybe the ff will help.
    >
    > You can map a welcome page, ie www.mycompany.com maps to
    > www.mycompany.com/helloppl.jsp
    >
    > Otherwise one accesses JSP's directly, for instance,
    > localhost/mywebapp/jspfolder/Hello.jsp


    Or it's simple to write a servlet that simply forwards (or redirects) to
    a JSP, and then map that.

    --
    www.designacourse.com
    The Easiest Way to Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
     
    Chris Smith, Apr 21, 2004
    #3
  4. Check down a bit in your web.xml, or possible server.xml or one of the
    ..xml config files, you should see something like
    <servlet>
    <servlet-name>jsp</servlet-name>
    <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
    <init-param>
    <param-name>logVerbosityLevel</param-name>
    <param-value>WARNING</param-value>
    </init-param>
    <load-on-startup>3</load-on-startup>
    </servlet>

    and then a bit down lower

    <!-- The mapping for the JSP servlet -->
    <servlet-mapping>
    <servlet-name>jsp</servlet-name>
    <url-pattern>*.jsp</url-pattern>
    </servlet-mapping>

    That's the only reason that .jsp files are interpreted as such.

    Oh, my bad, well I think this post might be relvant anyway so I'll
    post
    it anyway.

    So you want to map http://server/m to /foobar.jsp? Yeah, I would just
    set up a nice Redirector Servlet:

    public class RedirectorServlet extends HttpServlet {
    private String redirect = null;

    public void init() throws ServletException {
    this.redirect = getInitParameter("redirect");
    }

    public void doGet( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException {
    if (redirect == null)
    throw new ServletException("Cannot redirect to null.");
    else
    response.sendRedirect(redirect);
    }
    }

    and then have in your web.xml:
    <servlet>
    <servlet-name>redirector</servlet-name>
    <servlet-class>com.scovetta.Redirector</servlet-class>
    <init-param>
    <param-name>redirect</param-name>
    <param-value>/foobar.jsp</param-value>
    </init-param>
    </servlet>
    <servlet-mapping>
    <servlet-name>redirector</servlet-name>
    <url-pattern>/m</url-pattern>
    </servlet-mapping>

    That should handle what you want-- you might need to make the url
    pattern
    /m/* or /m*, I haven't tested it.

    Hope that helps--
    Mike Scovetta

    wrote in message news:<>...
    > I am using tomcat. In the web.xml for a webapp, I can do servlet mapping like
    >
    > <servlet-mapping>
    > <servlet-name>myServlet</servlet-name>
    > <url-pattern>/m</url-pattern>
    > </servlet-mapping>
    >
    > Can I map a jsp?
    >
    > Thanks,
    >
    > John
     
    Michael Scovetta, Apr 21, 2004
    #4
  5. javaexp

    Joined:
    Apr 18, 2013
    Messages:
    1
    Wanted to add more info to this old thread:

    Apart from using redirection, <jsp-file> tag, we can also map the servlet class file corresponding to that JSP. This servlet class is present in the work folder of any server like Tomcat, JBOSS.
     
    javaexp, Apr 18, 2013
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthias Nietz
    Replies:
    1
    Views:
    3,457
    VisionSet
    Nov 12, 2003
  2. Raymond DeCampo

    Custom tags and <jsp:plugin> / <jsp:param>

    Raymond DeCampo, Feb 18, 2004, in forum: Java
    Replies:
    0
    Views:
    639
    Raymond DeCampo
    Feb 18, 2004
  3. Replies:
    4
    Views:
    918
    Danno
    Apr 11, 2006
  4. Replies:
    0
    Views:
    4,403
  5. Replies:
    1
    Views:
    810
Loading...

Share This Page