2

I have several similar structures on the page. Each of the structure consists of a header and several checkboxes. In the java code I am creating a map for each set of data and pass them into the service.

On the main jsp page I get the service and can read these maps keys and values. But this way I will repeat the same code many times. So, I have to create something that looks like a function with a parameter, and that something will insert pieces of html code into the main page.

I can call included jsp file with a simple string parameter as here.

        <jsp:include page="groop_checkbox_with_header.jspf">
            <jsp:param name="mapName" value="investQuestionsExperience"/>
        </jsp:include>
        ....
        "${param.mapName}" - for use in the included jsp file

But I cannot set a parameter to a map. I could set a parameter to a map name and to get the map from the service/request/session using the map name inside the included jsp. But how to get the service/request/session in the called jsp file? It seems, I have to send a parameter with some non-trivial content.

But how?

I could use jsp tag instead of include. But the problems remains practically the same.

Please, notice, that I am using pure JSP without JSTL <c: > tags and I cannot use the last ones.

Gangnus
  • 24,044
  • 16
  • 90
  • 149
  • Create a custom tag. – Alan Hay Aug 24 '17 at 14:23
  • Using a tag, I again can pass only simple string parameters. And I need to pass a map. Or a name of the map, but then I have to pass service/request/session somehow. How can I get it there? – Gangnus Aug 24 '17 at 14:31
  • You cannot pass a Map using a *Parameter* however you can create a Map in java code and set this as a request *Attribute* for use in the JSP. http://learnjava4enterprise.blogspot.co.uk/2013/01/difference-between-attribute-and.html – Alan Hay Aug 24 '17 at 14:34
  • I think, your help to my another question will bring me to the working result faster, thank you. – Gangnus Aug 24 '17 at 14:37

1 Answers1

1

Well, into your included JSP, the request object is the same than the calling JSP's. You can always access it through pageContext.getRequest().

Same about the session (can access it through PageContext.getSession() or super-variable session), but I suggest you to use the request for this matter.

Little Santi
  • 8,563
  • 2
  • 18
  • 46