You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Shahed Ali <sm...@teleformix.com> on 2001/01/31 23:41:50 UTC

Re : extracting jsp file name

Sorry for the confusion.

I have a MVC framework in which  all jsp pages post
data to a controller servlet.

In this servlet, I need to findout which jsp page invoked it.

Currently I am passing a hidden variable with value="/callingpage.jsp"

i.e in  calling.jsp I have the code fragment

    <form action="/servlet/controller">
    <input type="hidden name=referer" value ="calling.jsp">
    </form>

I want to replace this with some jsp token in each page so that i dont have
to
hardcode the jsp page name in every page.

At first I thought of using the HTTP referer header in the servlet, but that
only works
for the first time. The servlet does a servlet forward(), and so the next
time I look at
the HTTP Referer header, I get the name of the servlet and not the jsp page
which called the servlet.

The only way I could think of is getting the generated class name in jsp and
UnMangling it.

I could either do that or write my own Mangler class.

Now I looked at the Mangler code in CommandLineCompiler.java from jasper.
The interface file Mangler.java has a comment that says that I can *plug in*
my own mangler.

However, would that mean rewriting CommandLineCompiler since it implements
Mangler ?

Thanks
Shahed


Re : extracting jsp file name

Posted by Kief Morris <ki...@bitbull.com>.
Shahed Ali typed the following on 04:41 PM 1/31/2001 -0600
>I have a MVC framework in which  all jsp pages post
>data to a controller servlet.
>
>In this servlet, I need to findout which jsp page invoked it.
>
>Currently I am passing a hidden variable with value="/callingpage.jsp"
...
>I want to replace this with some jsp token in each page so that i dont have
>to
>hardcode the jsp page name in every page.
...
>The only way I could think of is getting the generated class name in jsp and
>UnMangling it.

This seems like the very very hard way to do it. Use request.getServletPath()
in the JSP page and stash it in the session.

JSP page:

<% 
    session.setAttribute("domain.mine.myapp.jsp_page", request.getServletPath());
%>

Servlet:
    String jsp_page = request.getSession().getAttribute("domain.mine.myapp.jsp_page");
    if (jsp_page == null) {
        // uh, oh
    }

http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletRequest.html#getServletPath()

Kief