简体   繁体   English

是否可以将Spring MVC与预先存在的网页集成在一起?

[英]Is it possible to integrate Spring MVC and a pre-existing web page?

So, I have this Tomcat server. 所以,我有这个Tomcat服务器。 It's running some services which I'm using and I use it to support an existing application. 它正在运行我正在使用的某些服务,并使用它来支持现有的应用程序。 Separately, I have a standalone webapp developed using javascript and HTML. 另外,我有一个使用javascript和HTML开发的独立web应用程序。 It's in its own self-contained package-- a root folder with index.html and a bunch of subfolders containing the code. 它在自己的自包含程序包中-带有index.html的根文件夹和一堆包含代码的子文件夹。 It's got a little interactive part after which I need to store data from it. 它有一个互动的小部分,之后我需要存储其中的数据。

I want to host the webpage on my Tomcat server and then use spring MVC to build a simple web service to deal with receiving and persisting the data gained from the interactive part. 我想将网页托管在Tomcat服务器上,然后使用Spring MVC构建一个简单的Web服务,以处理从交互部分获得的数据并持久化。

I've taken a look at few other questions, but none have seemed to be what I'm looking for. 我看了其他几个问题,但似乎没有一个是我要寻找的。 Specifically, Is a parallel Spring-MVC application possible with a non-spring web app? 具体来说, 非Spring Web应用程序是否可以使用并行Spring-MVC应用程序? talks in general about using another thing (where I just want to literally serve that one HTML file) and everything I've read about how to set up Spring MVC starts talking about serving .jsp pages, which I don't have and don't want. 通常谈论使用另一种东西(我只想从字面上提供一个HTML文件),而我所读过的有关如何设置Spring MVC的所有内容都开始谈论为.jsp页面提供服务,而我没有也没有。不想。 One of the answers on How to access static resources when mapping a global front controller servlet on /* gets close to what I'm looking for, but instead of displaying an index.html it reroutes that file to a servlet, which is (I think?) exactly what I'm trying to avoid. 关于在/ *上映射全局前端控制器servlet时如何访问静态资源的答案之一接近于我要查找的内容,但是与其显示index.html,它不是将index.html重定向到servlet,而是(I想吗?)正是我要避免的事情。

Any advice for things to look into, or am I on a wild goose chase with this one? 对于要研究的事情有什么建议吗,或者我正在追赶这只鹅?

Maybe just create simple Java servlet project and map Spring dispatcher servlet to other url than root. 也许只是创建一个简单的Java servlet项目,并将Spring调度程序servlet映射到除root以外的其他URL。 Then your 'interactive part' might be at webapp root, which will be served by tomcat as a static content starting from url: 然后,您的“交互部分”可能位于webapp的根目录下,tomcat将以url开头的静态内容形式为其提供服务:

http://localhost:8080/mywebapp/

and spring webservice will be mapped to url: 并且spring webservice将映射到url:

http://localhost:8080/mywebapp/other_than_root/

You can configure servlet's mapping in web.xml: 您可以在web.xml中配置servlet的映射:

<web-app>
<servlet>
    <servlet-name>spring-mvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring-mvc</servlet-name>
    <url-pattern>/other_than_root/*</url-pattern>
</servlet-mapping>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM