开发者

How to include a controller from jsp page

I'm using Spring MVC.

I want to include menu page (named menu.jsp) with a controller (named MenuController) to my main page. If I call http://localhost:8080/myWeb/menu.htm everything is fine. But I try include menu into my main page like this :

<c:import url="menu.jsp"></c:import>
   Or  <c:import url="menu.htm"></c:import>

it shows nothing

This is config in dispatcher-servlet.xml file:

    <mvc:annotation-driven />

    <context:component-scan base-package="controllers" />


    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">

        <property name="prefix">
            <value>/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

and web.xml

  开发者_JAVA技巧<servlet>
    <servlet-name>dispatcher</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>dispatcher</servlet-name>
    <url-pattern>*.htm</url-pattern>
  </servlet-mapping>

Where am I wrong? Please help me. Thanks!


Try using <%@ include file="menu.jsp" %> or <jsp:include page="menu.jsp" />

By the way, no controller interferes here - this happens purely in the view.

On the other hand, if you want your controller to set some data required in the menu, then you should indeed use <c:import />. Not however that the path there is relative to the current page. So make sure it is correct.


I just discovered today you can trigger the controller by referencing the relative Spring url in the include.

<jsp:include page="/ConrollerRequestMapping/your/method/request/mapping"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜