一、实现目标
搭建网站门户系统(网站入口)
二、创建门户系统工程
1.创建Maven Project工程
2.添加依赖
<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">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<groupId>com.taotao</groupId>
<artifactId>taotao-portal</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<plugins>
<!-- 配置Tomcat插件 -->
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<configuration>
<port>8083</port>
<path>/</path>
</configuration>
</plugin>
</plugins>
</build>
</project>
三、添加配置文件
1.springmvc.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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">
<!-- controller扫描 -->
<context:component-scan base-package="com.taotao.portal.controller" />
<!-- 注解驱动 -->
<mvc:annotation-driven />
<!-- 视图解析器 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<!-- 配置前缀 -->
<property name="prefix" value="/WEB-INF/views/" />
<!-- 配置后缀 -->
<property name="suffix" value=".jsp" />
</bean>
<!-- 配置dubbo服务 -->
<!-- <dubbo:application name="taotao-portal" /> -->
<!-- 使用广播 -->
<!-- <dubbo:registry address="multicast://224.5.6.7:1234" /> -->
<!-- <dubbo:registry protocol="zookeeper" address="192.168.37.161:2181" /> -->
<!-- 声明要调用的服务,timeout是设置连接超时最长时间,如果不设置,超时时间默认是3秒 -->
<!-- <dubbo:reference interface="com.taotao.manager.service.ItemCatService" -->
<!-- id="itemCatService" timeout="1000000" url="dubbo://127.0.0.1:20880/"
/> -->
</beans>
2.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" version="2.5">
<display-name>taotao-portal</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<!-- 配置解决post提交乱码的问题 -->
<filter>
<filter-name>encoding</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>encoding</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<!-- 配置springMVC -->
<servlet>
<servlet-name>taotao-portal</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<!-- 设置springMVC配置文件 -->
<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>
<!-- 配置springMVC映射 -->
<servlet-mapping>
<servlet-name>taotao-portal</servlet-name>
<!-- 所有以html结尾的请求进入springMVC -->
<!-- 伪静态,SEO优化 -->
<url-pattern>*.html</url-pattern>
</servlet-mapping>
</web-app>
3.log4j.properties
log4j.rootLogger=DEBUG,A1
log4j.logger.com.taotao = DEBUG
log4j.logger.org.mybatis = DEBUG
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MM-dd HH:mm:ss,SSS} [%t] [%c]-[%p] %m%n
四、加入静态文件
五、实现首页访问
1.编写controller
package com.taotao.portal.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping("index")
public class IndexController {
/**
* 跳转到首页
* http://127.0.0.1:8083/index.html
* @return
*/
@RequestMapping(method = RequestMethod.GET)
public String toIndex() {
return "index";
}
}
2.配置ip和端口映射
3.配置Nginx,实现反向代理
(1)修改配置文件
(2)用管理员权限运行
(3)打开任务管理器,查看是否有对应进程
注:如果发现没有对应进程,很可能是80端口被占用,尝试用以下方法关闭80端口
查看占用80端口的进程
然后在任务管理器找到对应进程关闭
六、测试
成功!!!