搭建一个Web应用
因为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应用的更多相关文章
- 搭建一个web服务下载HDFS的文件
需求描述 为了能方便快速的获取HDFS中的文件,简单的搭建一个web服务提供下载很方便快速,而且在web服务器端不留临时文件,只做stream中转,效率相当高! 使用的框架是SpringMVC+HDF ...
- 搭建一个Web Server站点
题:搭建一个Web Server站点.安装web服务,并在本地创建index.html测试 1.安装http服务 yum -y install httpd 2.进入网站目录 cd /var/www/h ...
- 如何搭建一个WEB服务器项目(二)—— 对数据库表进行基本的增删改查操作
使用HibernateTemplate进行增删改查操作 观前提示:本系列文章有关服务器以及后端程序这些概念,我写的全是自己的理解,并不一定正确,希望不要误人子弟.欢迎各位大佬来评论区提出问题或者是指出 ...
- Spring Boot(一):如何使用Spring Boot搭建一个Web应用
Spring Boot Spring Boot 是Spring团队旗下的一款Web 应用框架 其优势可以更快速的搭建一个Web应用 从根本上上来讲 Spring Boot并不是什么新的框架技术 而是在 ...
- 搭建一个Web API项目(DDD)
传送阵:写在最后 一.创建一个能跑的起来的Web API项目 1.建一个空的 ASP.NET Web应用 (为什么不直接添加一个Web API项目呢,那样会有些多余的内容(如js.css.Areas等 ...
- 用Python手把手教你搭建一个web框架-flask微框架!
在之前的文章当中,小编已经教过大家怎么搭建一个Django框架,今天我们来探索另外的一种框架的搭建,这个框架就是web框架-flask微框架啦!首先我们带着以下的几个问题来阅读本文: 1.flask是 ...
- MyBatis整合Spring+SpringMVC搭建一个web项目(SSM框架)
本文讲解如何搭建一个SSM架构的web站点 [工具] IDEA.SqlYog.Maven [简述] 该项目由3个模块组成:dao(数据访问层).service(业务处理层).web(表现层) dao层 ...
- 使用Maven+ssm框架搭建一个web项目
1,前期准备:Eclipse(Mars.2 Release (4.5.2)).jdk1.7.tomcat7.maven3.2.1 2.使用eclipse中的maven新建一个web项目 点击next: ...
- 1.SpringBoo之Helloword 快速搭建一个web项目
背景: Spring Boot是由Pivotal团队提供的全新框架,其设计目的是用来简化新Spring应用的初始搭建以及开发过程.该框架使用了特定的方式来进行配置,从而使开发人员不再需要定义样板化的配 ...
随机推荐
- jQuery中的效果函数方法整理
注:以下所有的speed 参数可选,规定效果的时长.它可以取以下值:"slow"."fast" 或毫秒. 以下所有的callback 参数可选,是效果完成后所执 ...
- 实验12:Problem E: 还会用继承吗?
Home Web Board ProblemSet Standing Status Statistics Problem E: 还会用继承吗? Problem E: 还会用继承吗? Time Li ...
- C++中static类成员
static局部变量 static局部变量确保不迟于在程序执行流程第一次经过该对象的定义语句时进行初始化 这种对象一旦被创建,在程序结束前不会被撤销.在该函数被多次调用的过程中,静态局部对象会持续存在 ...
- 【转载】小米2进入recovery的方法
用过M1的朋友都多多少少的了解到~进入recovery是关机下同时 按 音量(+)+电源键. 其实M2也一样,但是我觉得是有点区别的. 在M1的时候,只要同时长按这两个键就可以的了. 但是M2呢?我发 ...
- IDO分享 | 如何在centos下安装OpenCMS
本次的opencms环境是在两台机器上搭建的. 一台服务器安装mySQL, 一台服务器安装jdk.tomcat.opencms.也可以将jdk.mySQL.tomcat.opencms安装在同一个机器 ...
- Java中的 WeakReference 和 SoftReference
我们知道Java语言中没有指针,取而代之的是引用reference.Java中的引用又可以分为四种:强引用,弱引用(WeakReference),软引用(SoftReference),虚引用(Phan ...
- poj 3667 Hotel(线段树,区间合并)
Hotel Time Limit: 3000MSMemory Limit: 65536K Total Submissions: 10858Accepted: 4691 Description The ...
- 用VB实现点名程序
用vb实现点名程序主要是随机变量的产生和数据的读取和存储以及计时器程序的设计,读取的文件命名为data.txt,书写格式为第一行为总人数下面的每行为一个人名,在应用时最好把data文件和程序文件放在一 ...
- curl -x 127.0.0.1:80
curl -x ip:80 +网址 就相当于在本地hosts文件指定一个域名,具有优先访问权.(curl -x 127.0.0.1:80这个方法适用于生产环境的服务器来测试自己做为代理商访问是否正常) ...
- volatile与synchronized关键字
volatile关键字相信了解Java多线程的读者都很清楚它的作用.volatile关键字用于声明简单类型变量,如int.float.boolean等数据类型.如果这些简单数据类型声明为volatil ...