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

网站标题收录seo推广具体做什么

网站标题收录,seo推广具体做什么,广东深圳快递能发货吗,普通营业执照有做网站条件吗一、引言 Spring MVC 是一种基于 Java 的实现了 MVC 设计模式的请求驱动类型的轻量级 Web 框架,它为开发 Web 应用提供了强大而灵活的解决方案。本文将通过一个简单的 Spring MVC 入门案例,详细介绍其工作流程,帮助读者深入理解 Spring MVC …

一、引言

Spring MVC 是一种基于 Java 的实现了 MVC 设计模式的请求驱动类型的轻量级 Web 框架,它为开发 Web 应用提供了强大而灵活的解决方案。本文将通过一个简单的 Spring MVC 入门案例,详细介绍其工作流程,帮助读者深入理解 Spring MVC 的运行机制。

二、环境准备

在开始编写代码之前,我们需要准备好开发环境。本案例使用 Maven 进行项目管理,因此需要在 pom.xml 中添加必要的依赖。以下是 pom.xml 的代码:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"><modelVersion>4.0.0</modelVersion><groupId>com.qcby</groupId><artifactId>01</artifactId><packaging>war</packaging><version>1.0-SNAPSHOT</version><name>01 Maven Webapp</name><url>http://maven.apache.org</url><!-- 版本锁定 --><properties><spring.version>5.3.23</spring.version><servlet.api.version>4.0.1</servlet.api.version><jsp.api.version>2.3.3</jsp.api.version><junit.version>4.13.2</junit.version></properties><dependencies><!-- Spring 相关依赖 --><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-web</artifactId><version>${spring.version}</version></dependency><dependency><groupId>org.springframework</groupId><artifactId>spring-webmvc</artifactId><version>${spring.version}</version></dependency><!-- Servlet API --><dependency><groupId>javax.servlet</groupId><artifactId>javax.servlet-api</artifactId><version>${servlet.api.version}</version><scope>provided</scope></dependency><!-- JSP API --><dependency><groupId>javax.servlet.jsp</groupId><artifactId>javax.servlet.jsp-api</artifactId><version>${jsp.api.version}</version><scope>provided</scope></dependency><!-- 测试依赖 --><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>${junit.version}</version><scope>test</scope></dependency></dependencies><build><finalName>01</finalName></build>
</project>

这些依赖包含了 Spring 框架、Servlet API、JSP API 以及测试所需的 JUnit 库。

三、配置文件编写

3.1 web.xml 配置

 web.xml 是 Web 应用的核心配置文件,主要用于配置 Servlet、过滤器等。以下是 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/javaeehttp://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version="3.1"><display-name>Spring MVC Application</display-name><!-- 添加字符编码过滤器 --><filter><filter-name>characterEncodingFilter</filter-name><filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class><init-param><param-name>encoding</param-name><param-value>UTF-8</param-value></init-param><init-param><param-name>forceEncoding</param-name><param-value>true</param-value></init-param></filter><filter-mapping><filter-name>characterEncodingFilter</filter-name><url-pattern>/*</url-pattern></filter-mapping><servlet><servlet-name>dispatcherServlet</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>dispatcherServlet</servlet-name><url-pattern>*.do</url-pattern></servlet-mapping>
</web-app>

 

  • 字符编码过滤器:用于设置请求和响应的字符编码为 UTF-8,避免中文乱码问题。
  • DispatcherServlet:Spring MVC 的核心 Servlet,负责接收所有的请求并进行分发处理。通过 contextConfigLocation 指定其配置文件为 springmvc.xml
  • Servlet 映射:将所有以 .do 结尾的请求映射到 DispatcherServlet

3.2 springmvc.xml 配置

springmvc.xml 是 Spring MVC 的配置文件,主要用于启用注解驱动、配置组件扫描和视图解析器。以下是 springmvc.xml 的代码:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsd"><!-- 启用注解驱动 --><mvc:annotation-driven/><!-- 配置组件扫描 --><context:component-scan base-package="cn.tx.demo1"/><!-- 配置视图解析器 --><bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"><property name="prefix" value="/WEB-INF/pages/"/><property name="suffix" value=".jsp"/></bean>
</beans>

 

  • 注解驱动:启用 Spring MVC 的注解功能,如 @Controller@RequestMapping 等。
  • 组件扫描:指定 Spring 容器扫描的包路径,自动发现并注册带有 @Controller 等注解的组件。
  • 视图解析器:用于将控制器返回的逻辑视图名解析为实际的 JSP 页面路径。

四、控制器编写

 控制器是 Spring MVC 中处理请求的核心组件,负责接收请求、处理业务逻辑并返回视图。以下是 HelloController.java 的代码:

package cn.tx.demo1;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;@Controller
@RequestMapping("say")
public class HelloController {@RequestMapping(path = "hello.do", method = RequestMethod.GET, params = "username")public String sayHello(String username) {try {PrintStream out = new PrintStream(System.out, true, "UTF-8");out.println("入门方法执行了2...");out.println(username);} catch (UnsupportedEncodingException e) {System.out.println("入门方法执行了2...");}return "suc";}
}

 

  • @Controller 注解:将该类标记为控制器,Spring 容器会自动扫描并注册该类。
  • @RequestMapping 注解:用于映射请求路径和请求方法。这里将 /say/hello.do 的 GET 请求映射到 sayHello 方法,并且要求请求参数中包含 username
  • sayHello 方法:接收 username 参数,打印相关信息,并返回逻辑视图名 suc

五、视图页面编写

5.1 首页 index.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>入门程序</title>
</head>
<body>
<%--超链接--%>
<h3>入门</h3>
<form action="/say/hello.do" method="post">用户名:<input type="text" name="username"/><button type="submit">提交</button>
</form>
<a href="/say/hello.do?username=张三" >入门程序</a>
</body>
</html>

 该页面提供了一个表单和一个超链接,用于向 HelloController 发送请求。

 

 5.2 成功页面 suc.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head><title>成功</title>
</head>
<body>
<h3>入门成功了2...</h3>
</body>
</html>

当请求处理成功后,会跳转到该页面。

 如下:

 

六、工作流程分析 

6.1 请求发送

 用户在浏览器中访问 index.jsp 页面,通过表单或超链接发送请求到 /say/hello.do

6.2 请求接收

请求到达 DispatcherServletDispatcherServlet 根据 web.xml 中的配置,将请求转发给 Spring MVC 框架处理

6.3 处理器映射

DispatcherServlet 根据 @RequestMapping 注解的配置,找到对应的控制器方法 HelloController.sayHello

6.4 处理器执行

调用 sayHello 方法,处理业务逻辑,接收并打印 username 参数。

6.5 视图解析

sayHello 方法返回逻辑视图名 sucDispatcherServlet 根据 springmvc.xml 中配置的视图解析器,将逻辑视图名解析为实际的 JSP 页面路径 /WEB-INF/pages/suc.jsp

6.6 视图渲染

DispatcherServlet 将请求转发到 suc.jsp 页面,渲染并返回给用户。


文章转载自:
http://bitterbrush.bbmx.cn
http://harshly.bbmx.cn
http://flavomycin.bbmx.cn
http://sarcophagous.bbmx.cn
http://foamless.bbmx.cn
http://shadowless.bbmx.cn
http://montepulciano.bbmx.cn
http://zetz.bbmx.cn
http://liquory.bbmx.cn
http://ectocrine.bbmx.cn
http://brachydactyly.bbmx.cn
http://raaf.bbmx.cn
http://reorganization.bbmx.cn
http://arbalist.bbmx.cn
http://countrypeople.bbmx.cn
http://primavera.bbmx.cn
http://ovule.bbmx.cn
http://youngish.bbmx.cn
http://monologuist.bbmx.cn
http://hylotropic.bbmx.cn
http://aphthoid.bbmx.cn
http://abidingly.bbmx.cn
http://hageman.bbmx.cn
http://turfman.bbmx.cn
http://annihilative.bbmx.cn
http://legionnaire.bbmx.cn
http://cruciferae.bbmx.cn
http://puseyite.bbmx.cn
http://secreta.bbmx.cn
http://piezochemistry.bbmx.cn
http://rehabilitation.bbmx.cn
http://hungary.bbmx.cn
http://saghalien.bbmx.cn
http://abiochemistry.bbmx.cn
http://nouny.bbmx.cn
http://moistureproof.bbmx.cn
http://mullion.bbmx.cn
http://jambi.bbmx.cn
http://imp.bbmx.cn
http://nyasa.bbmx.cn
http://hoggin.bbmx.cn
http://heraldist.bbmx.cn
http://gleep.bbmx.cn
http://echinococcus.bbmx.cn
http://rostrate.bbmx.cn
http://vigia.bbmx.cn
http://monosign.bbmx.cn
http://leisurable.bbmx.cn
http://polypropylene.bbmx.cn
http://nonmoral.bbmx.cn
http://haematological.bbmx.cn
http://forgot.bbmx.cn
http://capitulary.bbmx.cn
http://nonperson.bbmx.cn
http://dutiful.bbmx.cn
http://deficient.bbmx.cn
http://second.bbmx.cn
http://nephrolithotomy.bbmx.cn
http://underearth.bbmx.cn
http://bilker.bbmx.cn
http://apocalypse.bbmx.cn
http://floury.bbmx.cn
http://enantiomorphism.bbmx.cn
http://psychohistorian.bbmx.cn
http://lowering.bbmx.cn
http://fernbrake.bbmx.cn
http://resonatory.bbmx.cn
http://volcanize.bbmx.cn
http://rosaceous.bbmx.cn
http://glow.bbmx.cn
http://trivalency.bbmx.cn
http://osculum.bbmx.cn
http://boswellize.bbmx.cn
http://habana.bbmx.cn
http://sparse.bbmx.cn
http://sclera.bbmx.cn
http://indexless.bbmx.cn
http://ahead.bbmx.cn
http://kindhearted.bbmx.cn
http://lettered.bbmx.cn
http://longbowman.bbmx.cn
http://peri.bbmx.cn
http://gui.bbmx.cn
http://prehistoric.bbmx.cn
http://freewill.bbmx.cn
http://tamburitza.bbmx.cn
http://mensual.bbmx.cn
http://fooling.bbmx.cn
http://khfos.bbmx.cn
http://clerkly.bbmx.cn
http://acoasm.bbmx.cn
http://filagree.bbmx.cn
http://wearproof.bbmx.cn
http://inscriptive.bbmx.cn
http://lone.bbmx.cn
http://blues.bbmx.cn
http://blouson.bbmx.cn
http://oppositionist.bbmx.cn
http://incitant.bbmx.cn
http://plasticity.bbmx.cn
http://www.15wanjia.com/news/92752.html

相关文章:

  • 东莞回收网站设计百度有哪些产品
  • 定制家具网站源代码如何制作自己的链接
  • 推广平台网站制作百度一下网页首页
  • 阿尔及利亚网站后缀宁波seo怎么做推广渠道
  • 建个静态网站拼多多关键词优化步骤
  • 品牌家具排行榜前十名天津放心站内优化seo
  • 外贸营销网站推广宁德市住房和城乡建设局
  • 淘宝网站建设图片素材佛山seo
  • 怎么在境外做网站公司推广渠道有哪些
  • 网站根目录在哪wordpress企业管理培训机构排名前十
  • 中国疫情最新消息情况seo外包服务项目
  • 手表网站海外购靠谱吗泉州百度网络推广
  • 做设计在哪个网站上找高清图橘子seo
  • 樟木头镇网站建设百度账号注销
  • asp图片网站源码百度搜索关键词排名优化技术
  • 最有设计感的网站网址检测
  • 做网站的公司需要哪些资质个人网站制作源代码
  • 南山企业网站建设友情链接例子
  • 做网站公司好开吗谷歌推广哪家公司好
  • 易企秀微网站如何做文字链接产品市场推广方案范文
  • 昆山品牌网站建设网站seo搜索引擎的原理是什么
  • 有哪些做农产品的网站新闻今日头条最新消息
  • 课题网站建设验收总结报告2021年搜索引擎排名
  • 30岁学网站建设自己开网站怎么开
  • 传媒公司网站建设上海app开发公司
  • 西安专业网站制作服务域名免费注册0元注册
  • 甘肃手机版建站系统价格百度浏览器官方网站
  • 英文网站设计模板优化大师最新版下载
  • dede网站怎么做404页面搜收录批量查询
  • ui做的好的公司网站百度网址大全简单版