Java项目前后端分离-springmvc配置html视图解析器
来源:互联网 发布:面相分析软件 编辑:程序博客网 时间:2024/05/29 14:50
基于前后端分离的项目,是不用后端模板引擎的,所以什么以.jsp,.vm结尾的模板引擎也是用不了的,前端开发做好的项目用webpack打包之后放在了后端项目里面,直接配置html视图解析器,然后放心给所有静态资源,这样就能够直接把静态文件打包之后加打war包直接放在服务器上了,废话不多说,办法如下:
第一步:配置web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" version="3.1">
<welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/applicationContext-*.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <filter> <filter-name>CharacterEncodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>forceEncoding</param-name> <param-value>true</param-value> </init-param> </filter> <filter-mapping> <filter-name>CharacterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <servlet> <servlet-name>e3-manager</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <!-- contextConfigLocation不是必须的, 如果不配置contextConfigLocation, springmvc的配置文件默认在:WEB-INF/servlet的name+"-servlet.xml" --> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring/springmvc.xml</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>e3-manager</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping></web-app>这里说明一下,最好不要在servlet-mapping中配置资源过滤放行,原因很简单,Tomcat处理静态资源能力并不型,他是处理动态资源的能手。就这样。
第二步:在springmvc中配置html解析器
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/"/> <property name="suffix" value=".html"/> <property name="contentType" value="text/html"/> </bean>
<mvc:resources mapping="/css/**" location="/css/"/> <mvc:resources mapping="/js/**" location="/js/"/> <mvc:resources mapping="/fonts/**" location="/fonts/"/> <mvc:resources mapping="/style/**" location="/style/"/>或者直接所有静态资源直接全部放行:
<mvc:default-servlet-handler />
配置完了之后重启服务,就能访问你的静态页面。打包的时候直接打入war包,部署在服务器就行了!
阅读全文
1 0
- Java项目前后端分离-springmvc配置html视图解析器
- Nginx 前后端分离配置
- 前后端分离,java配置跨域请求问题
- 配置 cros Java 前后端分离跨域请求
- 前后端分离之Java后端
- 前后端分离springmvc和RESTful理解
- 前后端分离springmvc和RESTful理解
- 前后端分离springmvc和RESTful理解
- 前后端分离springmvc和RESTful理解
- 前后端分离springmvc和RESTful理解
- 前后端分离springmvc和RESTful理解
- spring-boot入门(三)前后端分离使用HTML视图
- 前后端分离项目实践分析
- 前后端分离项目实践分析
- 构建SpringMVCRestful前后端分离项目实例
- 前后端分离项目:后台管理
- 前后端分离项目shiro验证
- Javaweb项目如何做到前后端分离
- Moss 资料
- input 边框变色
- 窗体部件效果之设置背景色或图片
- 椭圆一般方程求解
- 校验同一时间只能存在一个起点到终点的数据,如何判断(时间,起点,终点)
- Java项目前后端分离-springmvc配置html视图解析器
- ubuntu 截图大全
- Android中featuredrecyclerview的使用
- 指向指针数据的指针
- react native Modal使用以及封装
- iOS NSMutableAttributedString 实现富文本
- Android studio Build APK报transformClassesWithDexForDebug问题
- Java关键字—final
- NO.1初识Objective-C