spring-mvc – 如何将“老式mvc控制器与jsp”和“vaadin7 ui”集成在一起

我正在尝试将vaadin与我的
spring mvc应用程序集成.

我有一些jsp文件的网址,弹簧mvc控制器使用它们

例如 :

              mysite.com/spring/

              mysite.com/spring/examples

              mysite.com/spring/examples/1.jsp

我想在这条路径中添加vaadin:
              mysite.com/vaadin/MainUI

这是我的web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_ID" version="3.1"
  xmlns="http://java.sun.com/xml/ns/j2ee" 
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
      http://java.sun.com/xml/ns/javaee/web-app_3_1.xsd"
      metadata-complete="true">

  <display-name>vaadin-spring</display-name>

  <!-- Turn off productionMode (off by default). Setting productionMode=true disables 
       debug features. In when this is off, you can show debug window by adding ?debug to 
       your application URL. Always set this true in production environment. -->
  <context-param>
    <param-name>productionMode</param-name>
    <param-value>false</param-value>
    <description>Vaadin production mode</description>
  </context-param>

  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:applicationContext.xml</param-value>
  </context-param>

  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <listener>
    <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
  </listener>

  <servlet>
    <servlet-name>vaadin-spring</servlet-name>
    <servlet-class>com.vaadin.terminal.gwt.server.ApplicationServlet</servlet-class>
    <init-param>
      <param-name>application</param-name>
      <param-value>com.practice.vaadin_spring.VaadinSpringDemoApplication</param-value>
      <description>Vaadin application class to start</description>
    </init-param>
  </servlet>

  <servlet-mapping>
        <servlet-name>vaadin-spring</servlet-name>
        <url-pattern>/vaadin/*</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>vaadin-spring</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>

  <!-- spring -->
  <servlet>
        <servlet-name>spring</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>spring.profiles.active</param-name>
            <param-value>local</param-value>
        </init-param>
  </servlet>
  <servlet-mapping>
        <servlet-name>spring</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

</web-app>

这是我的弹簧主控制器:

@Controller
@RequestMapping("/")
public class MainController {

    @RequestMapping(value = "{jspFile}")
    public String map(@PathVariable String jspFile) throws IOException {
        return jspFile;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String map1() throws IOException {
        return "index";
    }

}

这是github中的工作示例(修复后)
https://github.com/prilia/IntegrationSpringMvcVaadinUI

最佳答案 所以经过一些尝试后我最终得到了一个JSP编译异常,我认为这是合理的,因为你在github上提供了一个测试例子.

到目前为止,这就是我所做的:

web.xml中

<servlet-mapping>
  <servlet-name>spring</servlet-name>
  <url-pattern>/</url-pattern>
</servlet-mapping>

MainController.java

@Controller
@RequestMapping("/")
public class MainController { ...

我添加了spring-servlet.xml

<bean name="spring" class="org.nli.deposit.controller.MainController" />

现在好像它解析了网址:

http://localhost:8080/springMvcTest/转到JSP

http://localhost:8080/springMvcTest/vaadin去了Vaadin

它只是在JSP编译过程中崩溃,但这是另一个问题.
试试你的完整项目,让我知道!

点赞