工程结构与引用的jar包
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>spring-web-demo</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/spring-applicationContext.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:config/spring-mvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> </web-app>
spring-applicationContext.xml
<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" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <context:annotation-config/> <context:component-scan base-package="com.xx.demo.bsh"/> </beans>
<context:annotation-config/> 开启一些注入的注解功能
spring-mvc.xml
<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.1.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"> <mvc:annotation-driven/> <context:component-scan base-package="com.xx.demo.web"/> <mvc:resources location="/js/" mapping="/js/**"/> <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" > <property name="prefix" value="/WEB-INF/views/"></property> <property name="suffix" value=".jsp"></property> </bean> </beans>
<mvc:annotation-driven/> 开启注解Controller,RequestMapping的功能
TestController.java
package com.xx.demo.web.test; import javax.annotation.Resource; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import com.xx.demo.bsh.test.TestService; @Controller public class TestController { @Resource private TestService testService; @RequestMapping("/firstPage") public String testMethod(){ testService.print(); return "test"; } }
TestService.java
package com.xx.demo.bsh.test; import org.springframework.stereotype.Service; @Service("testService") public class TestService { public void print(){ System.out.println("这是服务层方法"); } }
test.jsp
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!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=utf-8"> <title>test page</title> </head> <body> test page </body> </html>
运行结果:
相关推荐
用最精简的struts2 jar包,开发一个可以入门学习struts2的例子,一看就能看懂的,并且配有博客,把步骤详细的写出来。
是一个非常成功的SSh项目。非常值得学习与借鉴。
Spring基础,适合新手学习 刚学Spring 写的web project
您将学习最受欢迎的Java框架,以使用Spring框架构建动态而强大的Web应用程序。 在本课程中,您将深入了解Spring Framework。 您还将了解Spring框架功能,例如Spring Boot,Spring容器,控制和依赖注入的反转,百里香...
Spring网络项目书 Spring Web项目从代码中学习(修订) 210208第01章
原生的web项目开发过程都是上面这样,和业务相关的其实只有第2步,而其他几个步骤是每个web项目都需要的,像比较大的项目,会有很多web模块,每个模块都需要重复这些1/3/4操作步骤,还是相当繁琐的,也会耗费大量...
目标SpringBoot研究学到了Java基本语法Spring Boot项目...JPA实际使用Spring Boot实用技巧通过查看由您自己使用Spring Boot和AWS实施的Web服务手册来学习项目内容创建一个CRUD板学到了深入了解Spring Boot的整体结构
下面开始正题:第一步:新建Web Project导入必要的jar包,目前只需导入(spring-core-4.1.6.RELEASE.jar、spring-beans-4.1.6.RELEASE.jar、spring-context-4.1.6.RELEASE.jar、spring-expression-4.1.6.RELEASE.jar...
在学习Spring Web Project书籍以学习代码时创建的一个实际示例。资料夹说明zex00_123p :: 123p的实践源(〜Part01.Ch05。模型2方法和Spring MVC)zex01_146p :: 146p的实际来源(〜Part01.Ch06.Spring + MyBatis)...
MySpringBoot That is a project for learning the springBoot 31.5. Using H2’s Web Console 31.5.1. Changing the H2 Console’s Path 31.6. Using jOOQ 31.6.1....31.6.2....2.该注解会在spring-boot
Spring启动项目该仓库中主要是Spring Boot的入门学习教程以及一些常用的Spring Boot实战项目教程,包括Spring Boot使用的各种示例代码,同时也包括一些实战项目的项目源码和效果展示,实战项目包括基本的web开发以及...
Barbershop_Web_Project 这是用于Barbershop管理的Web系统的一个项目,该项目正在使用Spring框架,Java和Bootstrap完成。 这个项目是由来自不同国家的程序员开发的,他们正在学习和提高他们的编程技能。
2 入门 8 2.1 下载 8 2.2 资源 8 2.3 环境准备 9 2.3.1 安装JDK 9 2.3.2 安装Ant 9 3 DEMO(官方例子)学习 9 3.1 下载安装包 9 3.2 启动DEMO 9 3.3 学习使用Eclipse设计器 10 3.4 学习使用JBPM控制台 11 3.5 学习...
导入方式:Myeclipse->Import->Maven4MyEclipse->Exsit Maven Project ###1.针对前端页面快速开发 说明:前台页面采用JSP作为视图 #####1.1提供了jsp页面继承标签,和两个自定义标签 在WEB-INF/views目录新建jsp页面...
我们正在编程一个Web应用程序,该应用程序将允许用户与朋友合作并使用编译器中的实时编辑功能,并且使分组学习更容易。 基本上,此Web应用程序将允许多个用户同时编写,编辑和编译编程语言。 该应用程序将使用时间轴...
使用Spring Web MVC和Rest Web Services进行开发安装初始化git仓库git init 克隆仓库git clone https://github.com/AnujaKoralage/WholeSalePOSWithSpringWebMvc.git 通过Intellij Idea导入项目贡献贡献使开源社区...
$ spring init --dependencies=web,data-jpa my-projectUsing service at https://start.spring.ioProject extracted to ' /Users/developer/example/my-project ' 购买的版本具有对Spring的高级支持,可直接在IDE...
电子医疗系统Web项目-使用Spring Boot安全-JPA-Rest-Thymeleaf-HQL(HMS) 生物医学与医院领域的项目,涵盖...oc new-app soumyadip007/E-Medical-System-Web-Project-Using-Spring-Boot-Security-MVC-Hibernate-JPA-R
这次集成版本是建Dynamic web Project,然后手动添加jar文件,配置文件而成。后面再出一个maven版本,废话不多说,我就开始写过程了。 首先三大框架基本概念: 一、SpringMvc 这里介绍SpringMVC我就不教课书似的...
全家桶学习套餐,计划学习的有Spring容器相关的IOC DI AOP相关知识,Spring的部分源码解析 Spring-Core [模块被总结] Core Container Core Container(核心容器)包含有Core、Beans、Context和Expression Language模块 ...