github地址:https://github.com/rongyaya10...
不使用Maven,创建SSH(Spring+SpringMVC+Hibernate)的方法:
IntelliJ idea
tomcat
新建Project
-
选择【Spring】 : Spring 、 Spring MVC 、 Web Application、Application Server、Hibernate
Spring和SpringMVC : 需要选择download,下载相关的jar
Web Application :会在WEB-INF下新建web.xml配置文件
Application Server:应用服务,配置Tomcat
Hibernate:需选择download,下载jar
下载jar,请稍等
目录结构
配置Project Structure
【File】-【Project Structure】
配置Modules
在src下,新建main - java (java目录变更Sources)
配置Problems
如果在Problems中有标的数字,请点击,选择【fix】-【Add...】
配置Artifacts(war模块)
配置Libraries(jar)
选择目录下的【lib】文件夹
添加:
目录结构:
配置文件修改
配置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">
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.form</url-pattern>
</servlet-mapping>
</web-app>
配置dispatcher-servlet.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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd">
<context:component-scan base-package="com.zgr.controller"/>
<mvc:annotation-driven/>
<mvc:default-servlet-handler/>
<bean id="jspViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>
下载 jstl.jar 1.2 和 standard.jar 1.1.2
http://repo2.maven.org/maven2...
http://repo2.maven.org/maven2...
导入jar
选择Problems,点击【fix】
更改目录结构,增加target文件夹,编译后文件可存入这个文件夹
更改文件夹后,修改
修改war:
配置tomcat
coding
【controller】- 新建IndexController.java
package com.zgr.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
public class IndexController {
@RequestMapping(value = "/", method = RequestMethod.GET)
public String index() {
return "index";
}
}
【pages】 - index.jsp
<%--
Created by IntelliJ IDEA.
User: zgr
Date: 2017/7/26
Time: 15:16
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>web</title>
</head>
<body>
web
</body>
</html>
运行:
成功!
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。