0

I need to show two URLs into a JSP, but I want to pass some init parameters to the JSP page for doing this.

So, this is my web.xml :

<web-app ... >
<servlet>
    <servlet-name>index1</servlet-name>
    <jsp-file>/index.jsp</jsp-file>
    <init-param>
        <param-name>p1</param-name>
        <param-value>http://www.google.com</param-value>
    </init-param>
    <init-param>
        <param-name>p2</param-name>
        <param-value>/pagina2.jsp</param-value>
    </init-param>
</servlet>
<servlet-mapping>
    <servlet-name>index1</servlet-name>
    <url-pattern>/index.jsp</url-pattern>
</servlet-mapping>

In the index.jsp, I wrote the following code:

<%
    // This is only a test code. Obviously, it doesn't show the URLs
      java.util.Enumeration e = getServletConfig().getInitParameterNames();
      while( e.hasMoreElements() ) {
          out.println( e.nextElement() + "<br>");
      }
    %>

But when I run the jsp, this show some initParameters that I don't need. By example: logVerbosityLevel
httpMethods
keepgenerated
p2 ----------- > This is the parameter that I need

xpoweredBy
p1 ----------- > This is other parameter that I need
system-jar-includes
com.sun.appserv.jsp.classpath

My questions is: Why the JSP file are using all this parameters?
Note: I'm using Glassfish.

CristianC
  • 15
  • 1
  • 6
  • Well now I've put all code into a Servlet. And it works now. But What does the other parameters mean? (logVerbosityLevel, httpMethods ...) – CristianC Dec 29 '12 at 17:02

1 Answers1

1

Those are the initialization parameters of the container-builtin JspServlet class who's responsible for serving JSP files. In case of Glassfish, you can find it in config/default-web.xml file of the domain. It's the servlet entry of org.apache.jasper.servlet.JspServlet (note, you should not modify it unless you really understand what you're doing).

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Thanks a lot, @BalusC. Well, I'm still learning Jsp 1.2, before seeing Jps 2.0 new features. I'll try to write what you said. Thanks again. – CristianC Dec 29 '12 at 19:32
  • Oh, sorry. I tried the first way: w But it generates a URL like that: w But I suppose I did something wrong. – CristianC Dec 29 '12 at 20:13
  • D'oh, sorry I mixed it up. In spite of the name `${initParam}`, it actually refers `` entires of `web.xml`. It's not possible to access JSP servlet init params in EL. I'll edit the answer to remove the incorrect information. – BalusC Dec 29 '12 at 20:21