SSM相关

SSM的完整工程可以在github上下载几个,具体路径:
https://github.com/search?q=ssm

https://gitee.com/search?utf8=✓&q=ssm&type=

简单几步从零开始搭建一个SSM项目:
https://blog.csdn.net/HelloWorld_In_Java/article/details/79191421

ssm框架最基本源码:
https://download.csdn.net/download/helloworld_in_java/10230214

eclipse下载:
https://www.eclipse.org/downloads/download.php?file=/technology/epp/downloads/release/indigo/SR2/eclipse-jee-indigo-SR2-win32-x86_64.zip

默认的classpath是在工程的build文件夹中。可将classpath改为配置放在WEB-INF中。更改操作为: 右键工程 -> Build Path -> Configure Build Path-> 找到Source栏 -> 修改Default output folder为: ssmDemo/WebContent/WEB-INF/classes )

JavaWeb:报错信息The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
原因:
Javaweb工程类中没有添加Tomcat运行时相关类导致。
解决方法:
1、右击web工程-》属性或Build Path-》Java Build Path->Libraries-> Add Libray…->Server Runtime -》Tomcat Server
2、切换到Java Build Path界面中的Orader and Export,选择Tomcat。

eclipse编译报错:Access restriction: The type Resource is not accessible due to restriction on required library D:\Program Files\Java\jre6\lib\rt.jar
解决方法:
Project -> Properties -> libraries,先remove掉JRE System Library,然后再Add Library重新加入。

eclipse编译报错:The import java.util cannot be resolved
错误原因:
原因:
这是由于你的项目buildpath不对
解决方案:
右键项目-------buildpath--------Config Build Path最下面那个configuration 的选择libraries找到JRE(这个时候你会发现这个jre前面有!或者是红X)选中remove掉重新为该项目选择一个JRE选中项目,project----clean
在这里插入图片描述

spring-mvc.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"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc
       					   http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
       					   http://www.springframework.org/schema/beans
						   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
						   http://www.springframework.org/schema/context
						   http://www.springframework.org/schema/context/spring-context-3.1.xsd">
						
		<context:component-scan  base-package="com.test.controller" />
		
		<mvc:annotation-driven />
		
		<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
			<property name="prefix" value="/WEB-INF/jsp/" />
			<property name="suffix" value=".jsp" />
		</bean>
</beans>

Eclipse中设置编码的方式:
1、windows->Preferences…打开"首选项"对话框,左侧导航树,导航到 general->Workspace,右侧Text file encoding,选择Other,改变为UTF-8,以后新建立工程其属性对话框中的Text file encoding即为UTF-8。
2、windows->Preferences…打开"首选项"对话框,左侧导航树,导航到 general->Content Types,右侧Context Types树,点开Text,选择Java Source File,在下面的Default encoding输入框中输入UTF-8,点Update,则设置Java文件编码为UTF-8。其他java应用开发相关的文件 如:properties、XML等已经由Eclipse缺省指定,分别为ISO8859-1,UTF-8,如开发中确需改变编码格式则可以在此指定。
3、经过上述两步,新建java文件即为UTF-8编码,Eclipse编译、运 行、调试都没问题,但是做RCP应用的Product输出时、或者插件输出时,则总是出错,要么不能编译通过(输出时要重新compile)、要么输出的 插件运行时中文显示乱码。此时需要再RCP应用、或插件Plugin工程的build.properties中增加一 行,javacDefaultEncoding… = UTF-8。让输出时编译知道java源文件时UTF-8编码。这个设置需要保证所有的java源文件时UTF-8编码格式,如果不全是,可以参考 Eclipse帮中(Plug-in Development Environment Guide > Reference > Feature and Plug-in Build configuration),建议全部java源文件是UTF-8编码。

Spirng-mvc依赖包下载地址:
https://blog.csdn.net/cb440510/article/details/19650659
http://www.java2s.com/Code/Jar/c/Downloadcommonslogging113jar.htm

简单几步从零开始搭建一个SSM项目:
https://blog.csdn.net/HelloWorld_In_Java/article/details/79191421

cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:annotation-driven’报错解决方法:
https://stackoverflow.com/questions/19218122/cvc-complex-type-2-4-c-the-matching-wildcard-is-strict-but-no-declaration-can

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

Spring MVC教程:
https://www.yiibai.com/spring_mvc/

史上最简单的 Spring MVC 教程(一):
https://blog.csdn.net/qq_35246620/article/details/54704656

自己的一部分SSM例子:
eclispe项目目录结构截图:
在这里插入图片描述
注意,这里的resources文件夹必须是Source Folder,而不是普通的Folder,不然web.xml会找不到该配置文件。

代码如下:

testController.java:

package com.test.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping(value="/testController")
public class TestController {

	@RequestMapping(value="/toTestPage")
	public Object test(Model model) {
		model.addAttribute("msg", "Go To test.jsp");
		return "test";
	}
}

spring-mvc.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"
       xsi:schemaLocation="http://www.springframework.org/schema/mvc
       					   http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
       					   http://www.springframework.org/schema/beans
						   http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
						   http://www.springframework.org/schema/context
						   http://www.springframework.org/schema/context/spring-context-3.1.xsd">
						
		<context:component-scan  base-package="com.test.controller" />
		
		<mvc:annotation-driven />
		
		<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
			<property name="prefix" value="/WEB-INF/jsp/" />
			<property name="suffix" value=".jsp" />
		</bean>
</beans>

test.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	${msg}
</body>
</html>

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_3_0.xsd" version="3.0">
  <display-name>ssmDemo</display-name>
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  
  <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:spring/spring-mvc.xml</param-value>
  	</init-param>
  	<load-on-startup>1</load-on-startup>
  	<async-supported>true</async-supported>
  </servlet>
  
  <servlet-mapping>
  	<servlet-name>SpringMVC</servlet-name>
  	<url-pattern>/</url-pattern>
  </servlet-mapping>
  
  
</web-app>

index.jsp:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
	Hello JSP!
</body>
</html>

在浏览器中输入:http://localhost:8080/ssmDemo/testController/toTestPage

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值