SSM相关

简介: 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

相关文章
|
10月前
|
前端开发 Java 数据库连接
SSM整合~
SSM整合~
|
2月前
|
前端开发 JavaScript Java
SSM
【6月更文挑战第6天】
15 1
|
2月前
|
Java 数据库连接 Maven
ssm整合
ssm整合
12 0
|
3月前
|
安全 数据管理 Java
基于ssm的新农大校园论坛系统
基于ssm的新农大校园论坛系统
43 1
|
3月前
|
Java 数据库连接 Spring
SSM整合
SSM整合
|
JSON 前端开发 JavaScript
SSM 之 SpringMVC(上)
SSM 之 SpringMVC(上)
60 0
|
Java 数据库连接 Spring
SSM整合(超详细)
新建一个excepition包包下创建所需各个异常类记得继承相应的异常父类,原因:程序运行时遇到相应异常后可以不处理向上抛不继承坏处:以后每个方法都要加上这个类//继承RuntimeException类 public class TestExcepition extends RuntimeException {//区别自定义异常类的编码 public TestExcepition(Integer code) {} }
125 1
SSM整合(超详细)
|
SQL 开发框架 前端开发
[ SSM ] 浅谈 SSM 框架(Spring+SpringMVC+MyBatis)
SSM ? 陌生吗 ?我敢说来看这篇文章的你肯定不陌生~~~哈哈哈哈 关于 SSM,我第一次接触应该是在大四,毕业论文开题报告之前的几天,我改题的时候。当时由于准备实习的一些事,没有太多时间去完成论文的研究,接受导师的建议于是改成了毕设,选定的就是 SSM 框架。 那么这篇文章呢,我想分享一下有关 SSM 框架的一些知识。
1114 0
[ SSM ] 浅谈 SSM 框架(Spring+SpringMVC+MyBatis)
|
数据安全/隐私保护
基于SSM的教学质量系统
本系统为2020年4月做的项目,基于SSM整合开发。主要包括系部教学工作质量评价、日常教学质量检查、教学检查评价结果分析、学生评教,教师教学信息等,主要分为四个角色。
基于SSM的教学质量系统
|
前端开发 JavaScript Java
基于SSM的家庭理财系统
该系统为原创的项目,创作于2020年12月,包含详细数据库设计。基于SSM整合,数据层为MyBatis,mysql数据库,具有完整的业务逻辑。适合于毕业设计、课程设计、数据库大作业等。
基于SSM的家庭理财系统