jsp mapping

H

homecurr

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
 
C

Chris Smith

kd said:
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
 
M

Michael Scovetta

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
 
Joined
Apr 18, 2013
Messages
1
Reaction score
0
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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top