因为EasyUI会涉及到与后台数据的交互,所以使用Spring MVC作为后台,搭建一个完整的Web环境

使用gradle作为构建工具

build.gradle

 group 'org.zln.lkd'
version '1.0-SNAPSHOT' apply plugin: 'jetty' sourceCompatibility = 1.8 repositories {
mavenLocal()
mavenCentral()
} dependencies {
compile(
"org.slf4j:slf4j-api:1.7.21",
"org.apache.logging.log4j:log4j-slf4j-impl:2.7",
"org.apache.logging.log4j:log4j-core:2.7",
"org.apache.logging.log4j:log4j-api:2.7",
"org.apache.commons:commons-lang3:3.3.2",
"org.springframework:spring-context:4.3.1.RELEASE",
"org.springframework:spring-aop:4.3.1.RELEASE",
"org.springframework:spring-core:4.3.1.RELEASE",
"org.springframework:spring-expression:4.3.1.RELEASE",
"org.springframework:spring-beans:4.3.1.RELEASE",
"org.springframework:spring-webmvc:4.3.1.RELEASE",
"org.springframework:spring-web:4.3.1.RELEASE",
"org.springframework:spring-jdbc:4.3.1.RELEASE",
"org.springframework:spring-tx:4.3.1.RELEASE",
"org.springframework:spring-test:4.3.1.RELEASE",
"org.springframework:spring-aspects:4.3.1.RELEASE",
"mysql:mysql-connector-java:5.1.32",
"com.alibaba:druid:1.0.9",
"org.mybatis:mybatis:3.4.1",
"org.mybatis:mybatis-spring:1.3.0",
"com.github.pagehelper:pagehelper:4.1.6",
"javax.servlet:javax.servlet-api:4.0.0-b01",
"jstl:jstl:1.2",
"com.fasterxml.jackson.core:jackson-databind:2.8.1"
) testCompile(
"junit:junit:4.12"
)
} // 自动创建好src目录 包括源码与测试源码
task mkdirs << {
sourceSets*.java.srcDirs*.each { it.mkdirs() }
sourceSets*.resources.srcDirs*.each { it.mkdirs() }
} // 显示当前项目下所有用于 compile 的 jar.
task listJars(description: 'Display all compile jars.') << {
configurations.compile.each { File file -> println file.name }
}

build.gradle

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"> <!--过滤器设置请求编码-->
<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>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> <welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list> </web-app>

web.xml

Spring初始化

AppInit.java

 package conf.spring;

 import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

 /**
* Spring初始化类
* Created by sherry on 16/11/28.
*/
public class AppInit extends AbstractAnnotationConfigDispatcherServletInitializer { /**
* Spring后台配置类
* @return
*/
@Override
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[]{AppRootConf.class};
} /**
* Spring MVC配置类
* @return
*/
@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[]{AppServletConf.class};
} /**
* 拦截地址呗Spring MVC处理
* @return
*/
@Override
protected String[] getServletMappings() {
return new String[]{"*.json","*.html","*.do","*.action","*.ajax"};
}
}

AppInit.java

AppRootConf.java

 package conf.spring;

 import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.FilterType;
import org.springframework.context.annotation.ImportResource;
import org.springframework.web.servlet.config.annotation.EnableWebMvc; /**
* Created by sherry on 16/11/28.
*/
@Configuration
//排除Spring MVC注解类
@ComponentScan(basePackages = {"org.zln"}, excludeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION, value = EnableWebMvc.class)})
@ImportResource("classpath:applicationContext.xml")
public class AppRootConf {
}

AppRootConf.java

AppServletConf.java

 package conf.spring;

 import org.springframework.context.annotation.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.JstlView; /**
* Created by sherry on 16/11/28.
*/
@Configuration
//开启MVC支持,同 <mvc:annotation-driven>
@EnableWebMvc
//仅扫描Controller注解的类
@ComponentScan(value = "org.zln",useDefaultFilters = false,includeFilters = {@ComponentScan.Filter(type = FilterType.ANNOTATION,value = Controller.class)})
@ImportResource("classpath:applicationContext-mvc.xml")
public class AppServletConf extends WebMvcConfigurerAdapter { /**
* 配置JSP视图解析器
* @return
*/
@Bean
public ViewResolver viewResolver(){
InternalResourceViewResolver resourceViewResolver = new InternalResourceViewResolver();
resourceViewResolver.setPrefix("/WEB-INF/jsp/");
resourceViewResolver.setSuffix(".jsp");
//JstlView表示JSP模板页面需要使用JSTL标签库,classpath中必须包含jstl的相关jar包;
resourceViewResolver.setViewClass(JstlView.class);
resourceViewResolver.setExposeContextBeansAsAttributes(true);
return resourceViewResolver;
} /**
* 配置静态资源的处理:要求DispatcherServlet将对静态资源的请求转发到Servlet容器默认的Servlet上,
* 而不是使用DispatcherServlet本身来处理
* @param configurer
*/
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
} }

AppServletConf.java

配置文件

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:p="http://www.springframework.org/schema/p"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.3.xsd"> </beans>

applicationContext.xml

 <?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.1.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">
<!--静态资源-->
<mvc:resources mapping="/css/**" location="/WEB-INF/css/"/> <!--<bean id="mappingJacksonHttpMessageConverter" class="org.springframework.http.converter.json.MappingJackson2HttpMessageConverter">-->
<!--<property name="supportedMediaTypes">-->
<!--<list>-->
<!--<value>text/html;charset=UTF-8</value>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
<!--<bean id="formHttpMessageConverter" class="org.springframework.http.converter.FormHttpMessageConverter"></bean>--> <!--<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter">-->
<!--<property name="messageConverters">-->
<!--<list>-->
<!--<ref bean="formHttpMessageConverter"/>-->
<!--<ref bean="mappingJacksonHttpMessageConverter"/>-->
<!--</list>-->
<!--</property>-->
<!--</bean>-->
</beans>

applicationContext-mvc.xml

 <?xml version="1.0" encoding="UTF-8"?>
<configuration status="OFF">
<!--appenders配置输出到什么地方-->
<appenders>
<!--Console:控制台-->
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</appenders> <loggers>
<!--建立一个默认的root的logger-->
<root level="trace">
<appender-ref ref="Console"/>
</root>
</loggers>
</configuration>

log4j2.xml

搭建一个Web应用的更多相关文章

  1. 搭建一个web服务下载HDFS的文件

    需求描述 为了能方便快速的获取HDFS中的文件,简单的搭建一个web服务提供下载很方便快速,而且在web服务器端不留临时文件,只做stream中转,效率相当高! 使用的框架是SpringMVC+HDF ...

  2. 搭建一个Web Server站点

    题:搭建一个Web Server站点.安装web服务,并在本地创建index.html测试 1.安装http服务 yum -y install httpd 2.进入网站目录 cd /var/www/h ...

  3. 如何搭建一个WEB服务器项目(二)—— 对数据库表进行基本的增删改查操作

    使用HibernateTemplate进行增删改查操作 观前提示:本系列文章有关服务器以及后端程序这些概念,我写的全是自己的理解,并不一定正确,希望不要误人子弟.欢迎各位大佬来评论区提出问题或者是指出 ...

  4. Spring Boot(一):如何使用Spring Boot搭建一个Web应用

    Spring Boot Spring Boot 是Spring团队旗下的一款Web 应用框架 其优势可以更快速的搭建一个Web应用 从根本上上来讲 Spring Boot并不是什么新的框架技术 而是在 ...

  5. 搭建一个Web API项目(DDD)

    传送阵:写在最后 一.创建一个能跑的起来的Web API项目 1.建一个空的 ASP.NET Web应用 (为什么不直接添加一个Web API项目呢,那样会有些多余的内容(如js.css.Areas等 ...

  6. 用Python手把手教你搭建一个web框架-flask微框架!

    在之前的文章当中,小编已经教过大家怎么搭建一个Django框架,今天我们来探索另外的一种框架的搭建,这个框架就是web框架-flask微框架啦!首先我们带着以下的几个问题来阅读本文: 1.flask是 ...

  7. MyBatis整合Spring+SpringMVC搭建一个web项目(SSM框架)

    本文讲解如何搭建一个SSM架构的web站点 [工具] IDEA.SqlYog.Maven [简述] 该项目由3个模块组成:dao(数据访问层).service(业务处理层).web(表现层) dao层 ...

  8. 使用Maven+ssm框架搭建一个web项目

    1,前期准备:Eclipse(Mars.2 Release (4.5.2)).jdk1.7.tomcat7.maven3.2.1 2.使用eclipse中的maven新建一个web项目 点击next: ...

  9. 1.SpringBoo之Helloword 快速搭建一个web项目

    背景: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...

随机推荐

  1. ESRI.ArcGIS.esriSystem名称空间问题

    在AO或AE开发中,并没有ESRI.ArcGIS.esriSystem这个dll,只有ESRI.ArcGIS.System,凡是需要ESRI.ArcGIS.esriSystem命名空间时,添加ESRI ...

  2. android布局--Android fill_parent、wrap_content和match_parent的区别

    来自:http://www.cnblogs.com/nikyxxx/archive/2012/06/15/2551390.html 三个属性都用来适应视图的水平或垂直大小,一个以视图的内容或尺寸为基础 ...

  3. Silverlight项目笔记2:.svc处理程序映射缺失导致的WCF RIA Services异常

    在确定代码.编译结果和数据库都正常的情况下,无法从数据库取到数据.错误提示:Sysyem.Net.WebException:远程服务器返回了错误:NotFound,监听发现请求数据库的服务异常,访问相 ...

  4. 深入理解java虚拟机(3)---类的结构

    计算机在开始的时候,只认识0和1,所以汇编语言是和机器结构或者说CPU绑定的.ARM体系结构就是这样一种体现,指令集的概念. 随着高级语言的出现,从字编码发展到了字节编码,计算机的先驱希望能够让语言能 ...

  5. 深入剖析js命名空间函数namespace

    在看阿里员工写的开源数据库连接池的druid的源代码时,发现了其中在jquery的原代码中又定义了一个命名空间的函数:$.namespace(),其代码如下: 网址为:https://github.c ...

  6. 关于Redis中交互的过程

    一.Redis启动 加载配置(命令行或者配置文件) 启动TCP监听,客户端的列表保存在redisserver的clients中 启动AE Event Loop事件,异步处理客户请求 事件处理器的主循环 ...

  7. PL/SQL之--游标

    一.游标简介 在PL/SQL中执行SELECT.INSERT.DELETE和UPDATE语句时,ORACLE会在内存中为其分配上下文区(Context Area),也称为缓冲区.游标是指向该区的一个指 ...

  8. 关于CPU Cache:程序猿需要知道的那些

    天下没有免费的午餐,本文转载于:http://cenalulu.github.io/linux/all-about-cpu-cache/ 先来看一张本文所有概念的一个思维导图: 为什么要有CPU Ca ...

  9. cocos2d-x之xml文件读取初试

    auto doc=new tinyxml2::XMLDocument(); doc->Parse(FileUtils::getInstance()->getStringFromFile(& ...

  10. spring提供的解决中文乱码方案

    在表单提交时,如果遇到中文符号会出现乱码问题. Spring提供一个CharacterEncodingFilter过滤器,可用于解决乱码问题. CharacterEncodingFilter使用的时候 ...