Discussions

Web tier: servlets, JSP, Web frameworks: Struts. Using include in views.

  1. Struts. Using include in views. (3 messages)

    I have two jsp - /contractor/listItem.jsp and /contractor/addCustomer.jsp,
    both have included /contractor/menu.jsp.
    listItem.jsp is view for ListItem.do.

    If we call http://localhost:8080/JSVS/ListItem.do then relative links in menu will resolved in different way
    from that we have if we call
    http://localhost:8080/JSVS/contractor/addCustomer.jsp

    How can I resolve this problem ?
  2. Dan,

    Define your links (that exist in menu.jsp) within your struts-config.xml file and link to these within your menu.jsp file using the <html:link> tag. Without sounding like a purist (stands back and waits for the onslaught!) linking directly to a JSP breaks the MVC model (which Struts is trying to assist you with!)

    Seeing as you are using includes (for your menu) you ~might~ want to take a look at using tiles. (If not for this project, then maybe for your future projects).

    You may wish to consider reading Professional Jakarta Struts (WROX) if you can pick up a copy of it; the last chapter 'Struts Cookbook' is worth the price of the book alone.

    Happy Strutting.
    Live with passion,
    AMB
  3. Struts. Using include in views.[ Go to top ]

    Tiles should indeed be a better approach. I would probably use the JSTL c:url tag instead of the html:link tag though. It is a more well defined standard and allows for more easily setting query string parameters, especially when you have more than one.
  4. Thank you for your replies.

    "Define your links (that exist in menu.jsp) within your struts-config.xml file and link to these within your menu.jsp file using the <html:link> tag."

    Using global forwards in my struts-config.xml with <html:link> will resolve my problem. And though it will break MVC model it suitable for me. But how tiles may help me ?
    Tiles is a good thing but I don't understand how can it help me ? I have read a couple of articles about Tiles, but I don't grasp how can I use it in my context.

    PS. I plan to use tiles in my projects to make layouts more driven