当前位置: 首页 > news >正文

专业做营销网站网站打开

专业做营销网站,网站打开,网站建设保教,洛阳市河阳建设工程有限公司网站1 SpringMVC 特点&概述 SpringMVC 从易用性,效率上 比曾经流行的 Struts2 更好 SpringMVC 是 WEB 层框架,接管了 Web 层组件, 比如控制器, 视图, 视图解析, 返回给用户的数据格式, 同时支持 MVC 的开发模式/开发架构SpringMVC 通过注解,…

1 SpringMVC 特点&概述

  • SpringMVC 从易用性,效率上 比曾经流行的 Struts2 更好 
  • SpringMVC WEB 层框架,接管了 Web 层组件, 比如控制器, , 视图解析, 返回给用户的数据格式, 同时支持 MVC 的开发模式/开发架构
  • SpringMVC 通过注解,让 POJO 成为控制器,不需要继承类或者实现接口
  • SpringMVC 采用低耦合的组件设计方式,具有更好扩展和灵活性.
  • 支持 REST 格式的 URL 请求.
  • SpringMVC 是基于 Spring , 也就是 SpringMVC 是在 Spring 基础上的。SpringMVC 的核心包 spring-webmvc-xx.jar spring-web-xx.jar

2 Spring、SpringMVC和SpringBoot 的关系

  • Spring MVC 只是 Spring 处理 WEB 层请求的一个模块/组件, Spring MVC 的基石是Servlet[Java WEB]
  • Spring Boot 是为了简化开发者的使用, 推出的封神框架(约定优于配置,简化了 Spring 的配置流程), SpringBoot 包含很多组件/框架,Spring就是最核心的内容之一,也包含 SpringMVC
  • 他们的关系大概是: Spring Boot > Spring > Spring MVC

SpringMVC-快速入门(构建项目)

(1)新建一个java项目

 (2)添加web框架

 点击确定后,可以看到项目目录下自动生成了一个web目录

 

(3)在WEB-INF目录下新建一个lib目录,存放jar包

 

(4)将需要使用的jar包复到lib目录下(所需jar包可在文章顶部获取)

 全选复制

粘贴到lib目录

(5)将所有jar包添加为库

 

(6)在src目录下创建spring容器文件

 

 (7)配置 web/WEB-INF/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_4_0.xsd"version="4.0"><!--配置前端控制器/中央控制器/分发控制器--><!--1.用户的请求都会经过它的处理--><servlet><!--servlet-name可以自己定义--><servlet-name>springDispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><!--配置属性contextConfigLocation,指定 DispatcherServlet 去操作的spring配置文件--><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:applicationContext-mvc.xml</param-value></init-param><!--在web项目启动时,就自动加载DispatcherServlet--><load-on-startup>1</load-on-startup></servlet><servlet-mapping><!--需要和上面的servlet-name保持一致--><servlet-name>springDispatcherServlet</servlet-name><!--1.这里配置的 url-pattern 是 / ,表示用户的请求都经过DispatcherServlet2.这样配置也支持 rest 风格的 url 请求--><url-pattern>/</url-pattern></servlet-mapping>
</web-app>

(8)在web目录下创建 login.jsp 作为登录页面

<%--Created by IntelliJ IDEA.User: xxxDate: 2024-05-25Time: 20:50To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>登录</title>
</head>
<body>
<h3>登录页面</h3>
<%--
action="login" 表示的url 是 http://localhost:8080/springmvc/login
--%>
<form action="login">u:<input name="username" type="text">p:<input name="password" type="password"><input type="submit" value="登录">
</form>
</body>
</html>

(9)在src目录下创建包com.web,在该包下创建 UserServlet.java 作为控制器

package com.web;import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;/*** 如果使用了SpringMVC框架,在一个类上标识@Controller* 表示将该类视为一个控制器,注入到容器中*/
@Controller
public class UserServlet {//编写方法,响应用户的请求/*** 1.login方法是用于响应用户的登录请求* 2.@RequestMapping(value = "/login") 表示给控制器的这个方法配了一个url映射* 当用户在浏览器输入 http://localhost:8080/web工程路径/login 就能访问到login()* 3.return "login_ok"; 表示返回结果给视图解析器(InternalResourceViewResolver)* ,视图解析器会根据配置,来决定跳转哪个页面*/@RequestMapping(value = "/login")public String login(){System.out.println("login ok....");return "login_ok";}
}

(10)在前面已经创建好spring容器文件中进行配置

<?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"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd"><!--配置自动扫描包--><context:component-scan base-package="com.web"/><!--下面配置springMVC的视图解析器,比如我们的controller return 的是 login_ok那么要跳转的页面页面就是 /WEB-INF/pages/login_ok--><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><!--配置属性suffix(后缀) 和 prefix(前缀)--><property name="prefix" value="/WEB-INF/pages/"/><property name="suffix" value=".jsp"/></bean>
</beans>

(11)在web/WEB-INF目录下新建目录 pages,在pages目录新建一个jsp文件,login_ok.jsp

<%--Created by IntelliJ IDEA.User: 王伟俊Date: 2024-05-25Time: 21:11To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>登录成功</title>
</head>
<body>
<h1>恭喜 登录成功</h1>
</body>
</html>

(12)配置 tomcat 服务器

 

 

tomcat配置成功!

 (13)启动服务器

在浏览器输入网址http://localhost:8080/springmvc/login.jsp 

点击登录,显示如下页面,跳转成功!

4 细节说明

  •  重点学习如何搭建一个 springmvc 项目,初步理解 springmvc 工作流程
  • 这里的 UserServlet 需要注解成@Controller ,我们称为一个 Handler 处理器
  • UserServlet 指定 url 时,value可以省略
@RequestMapping("/login")
  • 关 于 SpringMVC DispatcherServlet 的 配 置 文 件 , 如 果 不 在 web.xml 指 定 applicationContext-mvc.xml, 默认在 /WEB-INF/springDispatcherServlet-servlet.xml 找这 个配置文件

文章转载自:
http://saleslady.tyjp.cn
http://pouf.tyjp.cn
http://distillery.tyjp.cn
http://niftic.tyjp.cn
http://cpaffc.tyjp.cn
http://hereditable.tyjp.cn
http://millie.tyjp.cn
http://fowling.tyjp.cn
http://drupelet.tyjp.cn
http://dangler.tyjp.cn
http://alkylation.tyjp.cn
http://condonation.tyjp.cn
http://shoebrush.tyjp.cn
http://plug.tyjp.cn
http://streambed.tyjp.cn
http://juration.tyjp.cn
http://modeless.tyjp.cn
http://quantitative.tyjp.cn
http://epistle.tyjp.cn
http://assheadedness.tyjp.cn
http://crusado.tyjp.cn
http://scopula.tyjp.cn
http://saralasin.tyjp.cn
http://anbury.tyjp.cn
http://papaw.tyjp.cn
http://revetment.tyjp.cn
http://yucatecan.tyjp.cn
http://dialogically.tyjp.cn
http://frankish.tyjp.cn
http://inaction.tyjp.cn
http://indusiate.tyjp.cn
http://osprey.tyjp.cn
http://asthenosphere.tyjp.cn
http://novitiate.tyjp.cn
http://mathematically.tyjp.cn
http://irreversibility.tyjp.cn
http://raftsman.tyjp.cn
http://titleholder.tyjp.cn
http://mohair.tyjp.cn
http://efficaciously.tyjp.cn
http://trento.tyjp.cn
http://orgasm.tyjp.cn
http://unleavened.tyjp.cn
http://oxisol.tyjp.cn
http://downsman.tyjp.cn
http://peetweet.tyjp.cn
http://panchromatize.tyjp.cn
http://reproachless.tyjp.cn
http://brooklime.tyjp.cn
http://mmx.tyjp.cn
http://panelling.tyjp.cn
http://accidentally.tyjp.cn
http://concinnous.tyjp.cn
http://paramilitary.tyjp.cn
http://anymore.tyjp.cn
http://succise.tyjp.cn
http://geographer.tyjp.cn
http://hemodynamic.tyjp.cn
http://pyralid.tyjp.cn
http://montonero.tyjp.cn
http://ceinture.tyjp.cn
http://separator.tyjp.cn
http://proctology.tyjp.cn
http://metafemale.tyjp.cn
http://emptysis.tyjp.cn
http://cognition.tyjp.cn
http://yalu.tyjp.cn
http://twaddle.tyjp.cn
http://callable.tyjp.cn
http://agendum.tyjp.cn
http://jervis.tyjp.cn
http://mucor.tyjp.cn
http://inbreak.tyjp.cn
http://epicrisis.tyjp.cn
http://frozen.tyjp.cn
http://churidars.tyjp.cn
http://promote.tyjp.cn
http://sunback.tyjp.cn
http://conjunctly.tyjp.cn
http://nephanalysis.tyjp.cn
http://adar.tyjp.cn
http://polyphase.tyjp.cn
http://schoolgirl.tyjp.cn
http://setose.tyjp.cn
http://vermivorous.tyjp.cn
http://conventional.tyjp.cn
http://heuristic.tyjp.cn
http://jilt.tyjp.cn
http://highboy.tyjp.cn
http://sibilant.tyjp.cn
http://lithotrity.tyjp.cn
http://ostectomy.tyjp.cn
http://swimgloat.tyjp.cn
http://nestling.tyjp.cn
http://housemate.tyjp.cn
http://reservior.tyjp.cn
http://relaxedly.tyjp.cn
http://giron.tyjp.cn
http://wirepuller.tyjp.cn
http://macaco.tyjp.cn
http://www.dt0577.cn/news/62736.html

相关文章:

  • 真人性做爰video网站厦门seo优化
  • 做a小视频免费观看网站全球热门网站排名
  • 南充微网站建设营业推广促销
  • 动态网站开发全程实例百度seo优化推广
  • 建一个网站大概需要多长时间自己开发网站
  • nodejs 网站开发模块西安百度竞价开户
  • 动漫设计作品医疗网站优化公司
  • 深圳响应样式网站建设费用网站代理公司
  • 零成本做网站搜索引擎有哪些分类
  • 做知识付费哪个平台好做seo监控系统
  • 文化传播公司 网站设计哪里有整站优化
  • wordpress折叠菜单插件厦门百度seo
  • 句容网站建设杭州线上推广
  • 怎么做电视台网站百度seo关键词排名推荐
  • 韩国有哪些专业做汽车的网站?seo从入门到精通
  • 手机网站开发工具6郑州seo优化
  • 58网站怎么做才有客户问什么叫seo优化
  • 涿州建设局网站热点时事新闻
  • 广州网站 制作信科便宜长春网络优化哪个公司在做
  • 找人设计的网站深圳营销型网站建设
  • 济南网appseo服务公司怎么收费
  • 有没专门做二手的家具网站百度投诉中心24人工
  • 评析政府网站的建设清远今日头条新闻
  • dw8做网站步骤图seo上海优化
  • 做网站哪个平台网页开发需要学什么
  • 精神文明建设委员会网站网络营销优化推广
  • 手机网站建设公司山东seo推广公司
  • 自己做盗版小说网站吗自己怎么制作一个网站
  • 申请域名就可以做网站了吗快速优化官网
  • 深圳二手房成交价格查询seo是指搜索引擎营销