1.全部JAR文件(全部spring/logger/jdbc)放到WEB-INF/lib下面,不需要项目中引用(即不需要Build Path)。
基本文件列表:
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>spring</display-name>
<servlet>
<servlet-name>spring</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:config.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
</web-app>
spring-servlet.xml
<?xml version="1.0" encoding="UTF-8"?>
<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-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc.xsd">
<context:component-scan base-package="com.spring.controller"></context:component-scan>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
</beans>
config.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">
<bean name="/home" class="com.spring.controller.HomeController"></bean>
</beans>
HomeController.java
package com.spring.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
@Controller
public class HomeController {
@RequestMapping("/home")
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) {
ModelAndView mv = new ModelAndView();
mv.addObject("msg","hello Model View");
return mv;
}
}
home.jsp
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
hello ,I am home.${msg}
</body>
</html>
2.web.xml 里 写上:
<absolute-ordering/>
</web-app>
解决报重复项目的问题。
3.index.jsp index.html要放这WebContent要目录下,不是WEB-INF目录下,这个目录是受保护的。
4.有xml头问题点eclipse下project->clean解决。
5.解决POST数据中文问题:
<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>
6. 设置网站的默认页面:
a)第一种方式:在springmvcmybatis-servlet.xml 设置 mvc:view-controller 这个标签
首先要建好:/WEB-INF/jsp/index.jsp
第二种方式:在 Controller的方法前加上: RequestMapping("/")
@RequestMapping("/")
public String index() {
return "index";
}
即可。
7.从SVN中检出的项目,如果无法运行tomcat,则在开始时新建一个Server,即可。
Mac 下eclipse 打开文件乱码的解决方法:Mac OS 下 eclipse中文乱码解决方法(eclipse for mac 中文乱码)_goodpress的专栏-CSDN博客
Eclipse 中没有动态Web的解决方法:Eclipse新建项目时没有“Dynamic Web Project”选项解决方法_汉德深-超的博客-CSDN博客
8.Eclipse 与SVN集成:在 eclipse -> help -> eclipse marketplace 搜索 :subclipse 并安装,然后在项目右键->Team->share.
Eclipse配置SVN的几种方法及使用详情 - 艾子琼 - 博客园
9.lombok 与 eclipse 集成:
下载好后,在 eclipse.ini 文件最后加上:
-javaagent:C:\Program Files\Java\eclipse-2020-03\lombok-1.18.16.jar
10.Eclipse中文插件的安装:
install new software ,work with 添加 :之后等待加载完后选中文,重启即可。
https://download.eclipse.org/technology/babel/update-site/latest/
11.Eclipse 中集成 FTP:
- Go to 'Help' -> 'Install New Software' (in older Eclipses, this is called something a bit different)
- In the 'Work with:' drop-down, select your version's plugin release site. Example: for Kepler, this is
Kepler - Kepler Software Repository - In the filter field, type 'remote'.
- Check the box next to 'Remote System Explorer End-User Runtime'
- Click 'Next', and accept the terms. It should now download and install.
- After install, Eclipse may want to restart.
Using it, in Eclipse:
- Window -> Open Perspective -> (perhaps select 'Other') -> Remote System Explorer
- File -> New -> Other -> Remote System Explorer (folder) -> Connection (or type Connection into the filter field)
- Choose FTP from the 'Select Remote System Type' panel.
- Fill in your FTP host info in the next panel (username and password come later).
- In the Remote Systems panel, right-click the hostname and click 'connect'.
- Enter username + password and you're good!
- Well, not exactly 'good'. The RSE system is fairly unusual, but you're connected.
- And you're one smart cookie! You'll figure out the rest.