商城

商城簡介javascript

網上商城相似於,京東商城,天貓商城,會員能夠在商城中瀏覽商品,下訂單,以及參加各類活動。html

管理員,運營能夠在管理後臺系統中管理商品,訂單,會員等。java

客服能夠在後臺管理系統中處理用戶的詢問以及投訴mysql

分佈式系統架構

分佈式架構:nginx

把系統按照模塊拆分紅多個子模塊。git

把模塊拆分,使用接口通訊,下降模塊之間的耦合度。github

把項目拆分紅若干個子項目,不一樣的團隊負責不一樣的子模塊。web

增長功能只須要增長一個子項目,調用其它項目接口就行。redis

能夠靈活的進行分佈式部署spring

 

缺點

系統之間交互須要使用遠程通訊,接口開發增長工做量。

3.6  技術選型

數據庫:mysql

Dao層:mybatis 德魯伊(druid)

緩存:redis

搜索:solr

service:spring

web:springmvc,jstl,EasyUI,jsp,freemake

圖片服務器:FastDFS(分佈式文件系統)

反向代理服務器:nginx

定時器:Quartz

Web服務器:tomcat

遠程調用:zookeeper,dubbo

工程管理:maven

4   後臺管理系統搭建

工程分析

網站通常分前臺和後臺,前臺給用戶看後臺是給管理人員看。

使用maven管理工具

一、依賴管理

二、項目構建

後臺建立一個獨立的web項目,建立一個maven工程打包方式是war包

ego-parent(父工程管理jar包的版本)

ego-commons (把通用的工具類打包)

ego-mananger(繼承父工程 pom文件)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>ego_parent</artifactId>
        <groupId>com.github.ego.parent</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../ego_parent/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

  <groupId>com.github.ego.manager</groupId>
  <artifactId>ego_manager</artifactId>
    <packaging>pom</packaging>

  <name>ego_manager</name>
  <url>http://maven.apache.org</url>
    <modules>
        <module>../ego_manager_domain</module>
        <module>../ego_manager_mapper</module>
        <module>../ego_manager_service</module>
        <module>../ego_manager_web</module>
    </modules>

    <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
      <!--依賴於ego_commons-->
    <dependency>
        <groupId>com.github.ego.commons</groupId>
        <artifactId>ego_commons</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </dependency>
  </dependencies>
    <build>
        <!-- 配置tomcat插件 -->
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <port>5050</port>
                    <path>/ego_manager</path>
                </configuration>

                <!--  <configuration>
                      <url>http://192.168.239.10:8080/manager/text</url>
                      <server>tomcat</server>
                      <path>/ego_manager</path>
                  </configuration>-->
            </plugin>
        </plugins>
    </build>
</project>

ego_manager_domain  (pom文件)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <parent>
        <artifactId>ego_manager</artifactId>
        <groupId>com.github.ego.manager</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../ego_manager/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>

  <groupId>com.github.ego.manager</groupId>
  <artifactId>ego_manager_domain</artifactId>
    <packaging>jar</packaging>

  <name>ego_manager_domain</name>
  <url>http://maven.apache.org</url>

  <properties>
      <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
      <!--單元測試-->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <scope>test</scope>
    </dependency>
  </dependencies>
</project>

domain

 
 
package com.bjsxt.domain;

//商品的domain類
public class Product extends BaseDomain{

private Integer flowerid ; //鮮花編號
private String flowerisbn; //鮮花
private String flowertype; //鮮花的象徵
private String flowername; //鮮花名字
private String flowermaterial; //鮮花材料
private String flowerpack; //鮮花包裹
private String flowerdesc; //鮮花描述
private String flowerimage; //鮮花圖片
private Double price; //鮮花價格
private Double currentprice; //當前價格
private String deliverarea ; //銷售地區
private String notetime; //筆記時間
private Integer status; //狀態碼
private Integer typeid; //類型編號


public Integer getFlowerid() {
return flowerid;
}
public void setFlowerid(Integer flowerid) {
this.flowerid = flowerid;
}
public String getFlowerisbn() {
return flowerisbn;
}
public void setFlowerisbn(String flowerisbn) {
this.flowerisbn = flowerisbn;
}
public String getFlowertype() {
return flowertype;
}
public void setFlowertype(String flowertype) {
this.flowertype = flowertype;
}
public String getFlowername() {
return flowername;
}
public void setFlowername(String flowername) {
this.flowername = flowername;
}
public String getFlowermaterial() {
return flowermaterial;
}
public void setFlowermaterial(String flowermaterial) {
this.flowermaterial = flowermaterial;
}
public String getFlowerpack() {
return flowerpack;
}
public void setFlowerpack(String flowerpack) {
this.flowerpack = flowerpack;
}
public String getFlowerdesc() {
return flowerdesc;
}
public void setFlowerdesc(String flowerdesc) {
this.flowerdesc = flowerdesc;
}
public String getFlowerimage() {
return flowerimage;
}
public void setFlowerimage(String flowerimage) {
this.flowerimage = flowerimage;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public Double getCurrentprice() {
return currentprice;
}
public void setCurrentprice(Double currentprice) {
this.currentprice = currentprice;
}
public String getDeliverarea() {
return deliverarea;
}
public void setDeliverarea(String deliverarea) {
this.deliverarea = deliverarea;
}
public String getNotetime() {
return notetime;
}
public void setNotetime(String notetime) {
this.notetime = notetime;
}
public Integer getStatus() {
return status;
}
public void setStatus(Integer status) {
this.status = status;
}
public Integer getTypeid() {
return typeid;
}
public void setTypeid(Integer typeid) {
this.typeid = typeid;
}



}
 

BaseDomain

package com.bjsxt.domain;

public class BaseDomain {
     private Integer page; //當前頁
     private Integer rows; //每頁的數量
    public Integer getPage() {
        return page;
    }
    public void setPage(Integer page) {
        this.page = page;
    }
    public Integer getRows() {
        return rows;
    }
    public void setRows(Integer rows) {
        this.rows = rows;
    }
     
     
}

 

ego_manager_mapper  (pom文件)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>ego_manager</artifactId>
<groupId>com.bjsxt.ego.manager</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../ego_manager/pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<groupId>com.bjsxt.ego.manager</groupId>
<artifactId>ego_manager_mapper</artifactId>
<packaging>jar</packaging>

<name>ego_manager_mapper</name>
<url>http://maven.apache.org</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>

<!--單元測試-->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</dependency>

<!-- 依賴ego_manager_domain -->
<dependency>
<groupId>com.bjsxt.ego.manager</groupId>
<artifactId>ego_manager_domain</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

<!-- Mybatis -->
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis</artifactId>
</dependency>
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
</dependency>
<dependency>
<groupId>com.github.miemiedev</groupId>
<artifactId>mybatis-paginator</artifactId>
</dependency>
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
</dependency>
<!-- MySql -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<!-- 鏈接池 -->
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
</dependency>

</dependencies>

<!-- 若是不添加此節點mybatis的mapper.xml文件都會被漏掉。 -->
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>


</project>

mapper文件 (productMapper.java)

package com.bjsxt.mapper;

import com.bjsxt.domain.Product;

import java.util.List;

public interface ProductMapper {
    
    //向數據庫中添加鮮花
    void addProduct(Product product);
    
    //查詢全部
    List<Product> loadProduct();
}

mapper配置文件  (productMapper.xml文件)

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
     PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
     "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
     
     <!-- 映射文件 -->
     <mapper namespace="com.bjsxt.mapper.ProductMapper">
         <insert id="addProduct" parameterType="com.bjsxt.domain.Product">
             insert
                into flower
                 values
                 (null,
                 #{flowerisbn},
                 #{flowertype},
                 #{flowername},
                 #{flowermaterial},
                 #{flowerpack},
                 #{flowerdesc},
                 #{flowerimage},
                 #{price},
                 #{currentprice},
                 #{deliverarea},
                 #{notetime},
                 #{status},
                 #{typeid})
         </insert>
         
         <!-- 查詢全部商品信息 -->
         <select id="loadProduct" resultType="com.bjsxt.domain.Product">
              select
              *
              from flower
         </select>
      
     </mapper>
     

ego-manager-service

package com.bjsxt.service;

import com.bjsxt.vo.ProductVo;
import com.bjsxt.vo.DataGridModel;

public interface ProductService {
   
    //添加鮮花
    void addProduct(ProductVo pvo);
    
    //查詢全部的鮮花產品
    DataGridModel<ProductVo> loadProductService(ProductVo pvo);
}
package com.bjsxt.service.impl;

import com.bjsxt.domain.Product;
import com.bjsxt.mapper.ProductMapper;
import com.bjsxt.service.ProductService;
import com.bjsxt.utils.DateUtils;
import com.bjsxt.vo.DataGridModel;
import com.bjsxt.vo.ProductVo;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service //將產品歸入到spring容器中
public class ProductServiceImpl  implements ProductService {

    //注入代理對象
    @Autowired
    private ProductMapper productMapper;
    
    @Override
    public void addProduct(ProductVo pvo) {
        //設置日期
        pvo.setNotetime(DateUtils.getFormateDate());
        //設置正常消費
        pvo.setStatus(1);
        //添加商品信息
        productMapper.addProduct(pvo);
    }

    
    @Override
    public DataGridModel<ProductVo> loadProductService(ProductVo pvo) {
        
        //建立dataGridModel對象
        DataGridModel<ProductVo> dgm = new DataGridModel<ProductVo>();
        
        //分頁對象
         Page page = PageHelper.startPage(pvo.getPage(), pvo.getRows());
        
        //建立product對象
        List<Product> loadProduct = productMapper.loadProduct();
        
        //遍歷
        for (Product product : loadProduct) {
            
            //建立productVo對象
            ProductVo productvo = new ProductVo();
            BeanUtils.copyProperties(product, productvo);
            dgm.getRows().add(productvo);
        }

        //設置總數
        dgm.setTotal(page.getTotal());
        return dgm;
    }

}

vo對象DataGridModel

package com.bjsxt.vo;

import java.util.ArrayList;
import java.util.List;

//datagrid:完成數據的列表的分頁顯示
public class DataGridModel<T> {
       
    //須要響應的總行 
      private Long total;
      private List<T> rows = new ArrayList<T>();
      
    public Long getTotal() {
        return total;
    }
    public void setTotal(Long total) {
        this.total = total;
    }
    public List<T> getRows() {
        return rows;
    }
    public void setRows(List<T> rows) {
        this.rows = rows;
    }
      
      
}

productVo對象

package com.bjsxt.vo;

import com.bjsxt.domain.Product;

public class ProductVo extends Product{

}

ego-manager-web(pom文件)對象

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
    <parent>
        <artifactId>ego_manager</artifactId>
        <groupId>com.bjsxt.ego.manager</groupId>
        <version>0.0.1-SNAPSHOT</version>
        <relativePath>../ego_manager/pom.xml</relativePath>
    </parent>
    <modelVersion>4.0.0</modelVersion>
  <groupId>com.bjsxt.ego.manager</groupId>
  <artifactId>ego_manager_web</artifactId>
  <packaging>war</packaging>
    <name>ego_manager_web Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
      <!-- 依賴ego_manager_service -->
      <dependency>
          <groupId>com.bjsxt.ego.manager</groupId>
          <artifactId>ego_manager_service</artifactId>
          <version>0.0.1-SNAPSHOT</version>
      </dependency>
      <dependency>
          <groupId>org.springframework</groupId>
          <artifactId>spring-webmvc</artifactId>
      </dependency>

      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>servlet-api</artifactId>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>javax.servlet</groupId>
          <artifactId>jsp-api</artifactId>
          <scope>provided</scope>
      </dependency>
      <dependency>
          <groupId>jstl</groupId>
          <artifactId>jstl</artifactId>
      </dependency>

      <dependency>
          <groupId>commons-fileupload</groupId>
          <artifactId>commons-fileupload</artifactId>
      </dependency>

  </dependencies>
  <build>
      <finalName>ego_manager_web</finalName>
  </build>
</project>

productController

package com.bjsxt.controller;

import com.bjsxt.service.ProductService;
import com.bjsxt.utils.FtpUtils;
import com.bjsxt.vo.DataGridModel;
import com.bjsxt.vo.ProductVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;
import java.util.UUID;

@Controller
public class ProductController {

//注入service對象
@Autowired
private ProductService productService;

@RequestMapping("/jumping")
public String jumping(){
return "index.jsp";
}

@RequestMapping("/addProductUI")
public String loadProduct(){
return "addProduct";

}

//跳轉產品的ui界面
@RequestMapping("/loadProductUI")
public String loadProductUI(){
return "productList";
}

//處理商品的添加
@RequestMapping("/addProduct")
public String addProduct(ProductVo pvo , MultipartFile mf){
try {
//圖片路徑
String newname = UUID.randomUUID().toString().replace("-", "");
String oldname = mf.getOriginalFilename();
String ext = oldname.substring(oldname.lastIndexOf("."));
newname = newname +ext;

//將上傳文件訪問輸入流對象
InputStream is = mf.getInputStream();
FtpUtils.ftpFileUpload("192.168.239.113", 21, "ftpuser", "ftpuser", "/home/ftpuser/images", newname, is);

String flowerimage = "http://www.wugui.com/"+newname;
//保存圖片
pvo.setFlowerimage(flowerimage);

//添加產品
productService.addProduct(pvo);


} catch (IOException e) {
e.printStackTrace();
}
return "productList";
}

//查詢全部產品信息
@RequestMapping("/loadProductList")
@ResponseBody
public DataGridModel<ProductVo> loadProductList(ProductVo pvo){
return productService.loadProductService(pvo);
}



}

ckeditController

package com.bjsxt.controller;

import com.bjsxt.utils.FtpUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.UUID;
/**
 * Created by asus on 2017/12/8.
 */
@Controller //將ckedit歸入到spring容器中
public class CkeditController {

    //處理ckedit文件上傳請求
    @RequestMapping("/ckeditUpload")
    @ResponseBody
    public String ckeditUpload(MultipartFile upload , String CKEditorFuncNum){

        try {
            //圖片路徑
            String newname = UUID.randomUUID().toString().replace("-", "");
            String oldname = upload.getOriginalFilename();
            String ext = oldname.substring(oldname.lastIndexOf("."));
            newname = newname +ext;

            //將文件上傳訪問輸入流對象
            InputStream is = upload.getInputStream();

            FtpUtils.ftpFileUpload("192.168.239.113", 21, "ftpuser", "ftpuser", "/home/ftpuser/images", newname, is);

            String flowerimage = "http://www.wugui.com/"+newname;

            //建立stringbuffer
            StringBuffer sbf = new StringBuffer();
            sbf.append("<script type=\"text/javascript\">");
            sbf.append("window.parent.CKEDITOR.tools.callFunction("+ CKEditorFuncNum + ",'" +flowerimage+ "','')");
            sbf.append("</script>");
            System.out.println(sbf.toString());
            return sbf.toString();

        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        }
        return null;
    }

}

applicationMapper.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd">


<!--實例化數據庫鏈接池-->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource">
<property name="driverClassName" value="com.mysql.jdbc.Driver"></property>
<!--<property name="url" value="jdbc:mysql://localhost:3306/ego"></property>-->
<property name="url" value="jdbc:mysql://192.168.239.10:3306/ego"></property>
<property name="username" value="root"></property>
<property name="password" value="root"></property>
</bean>

<!--建立sqlSessionFactory工廠 實例化sqlSessionFactory spring整合mybatis 不須要映射文件-->
<bean id="sessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<!--給sqlSessionFactory 注入dataSource -->
<property name="dataSource" ref="dataSource"></property>

<!-- 配置分頁插件 -->
<property name="plugins">
<list>
<bean class="com.github.pagehelper.PageHelper">
<property name="properties">
<props>
<prop key="dialect">mysql</prop>
<prop key="reasonable">true</prop>
</props>
</property>
</bean>
</list>
</property>

</bean>

<!-- 經過mapperScaner掃描,產生mapper的代理對象 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<!-- 指定要掃描的包 -->
<property name="basePackage" value="com.bjsxt.mapper"></property>
<!-- 注入sqlSessionFactory對象 -->
<property name="sqlSessionFactoryBeanName" value="sessionFactory"></property>
</bean>
</beans>

applicationService.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">

<!-- 自定義掃描 -->
<context:component-scan base-package="com.bjsxt.service"></context:component-scan>

<!-- 配置事物管理器 實例化事物管理器對象-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"></property>
</bean>

<!-- 配置開啓事物的操做 -->
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<!-- 指定在鏈接方法上面應用事物的屬性 -->
<tx:method name="add*" propagation="REQUIRED" read-only="false"/>
<tx:method name="update*" propagation="REQUIRED" read-only="false"/>
<tx:method name="delete*" propagation="REQUIRED" read-only="false"/>
<tx:method name="save*" propagation="REQUIRED" read-only="false"/>
<tx:method name="load*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="REQUIRED"/>
<!-- 對於其餘方法使用默認的事物管理器 -->
<tx:method name="*"/>

</tx:attributes>
</tx:advice>

<!-- 事物的aop配置 -->
<aop:config>
<!--切點 advice-ref 切面 pointcut-ref-->
<aop:pointcut expression="execution(* com.bjsxt.service.impl.*.*(..))" id="pc"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="pc"/>
</aop:config>


</beans>

springmvc.xml文件

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">

<!-- 開啓主鍵掃描 -->
<context:component-scan base-package="com.bjsxt.controller"/>

<!-- springmvc的註解驅動 -->
<mvc:annotation-driven/>

<!-- 配置視圖解析器 -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/" />
<property name="suffix" value=".jsp" />
</bean>

<!-- 文件上傳配置文件 -->
<bean id="multipartResolver"
class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<property name="defaultEncoding" value="UTF-8"></property>
<property name="maxUploadSize" value="1024000000"></property>
</bean>

</beans>

web.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xmlns="http://java.sun.com/xml/ns/javaee"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
  http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>ego</display-name>
  <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>

  <!-- 加載spring的配置文件 -->
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath*:application*.xml</param-value>
  </context-param>


  <!-- 配置監聽器 -->
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

  <!-- 處理springmvc的中文亂碼 -->
  <filter>
    <filter-name>charset</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>charset</filter-name>
    <url-pattern>*.action</url-pattern>
  </filter-mapping>

  <!-- 配置springmvc的核心控制器 -->
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

    <!-- 初始化參數 -->
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:springmvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>*.action</url-pattern>
  </servlet-mapping>

</web-app>
相關文章
相關標籤/搜索