• Welcome to the world's largest Chinese hacker forum

    Welcome to the world's largest Chinese hacker forum, our forum registration is open! You can now register for technical communication with us, this is a free and open to the world of the BBS, we founded the purpose for the study of network security, please don't release business of black/grey, or on the BBS posts, to seek help hacker if violations, we will permanently frozen your IP and account, thank you for your cooperation. Hacker attack and defense cracking or network Security

    business please click here: Creation Security  From CNHACKTEAM

Recommended Posts

需求分析

wejwq1qcf2t3170.png

编写过程

1.导入相关jar包

?可扩展标记语言版本='1.0 '编码='UTF八号'?

项目xmlns=' http://maven。阿帕奇。org/POM/4。0 .0 ' xmlns : xsi=' http://www。w3。' org/2001/XML架构-实例'

xsi :架构位置=' http://maven。阿帕奇。org/POM/4。0 .0 http://maven.apache.org/xsd/maven-4.0.0.xsd'

型号版本4 .0 .0/型号版本

groupIdcom.czy/groupId

artifactIdspringmvc _ day 01 _ 01 _ start/artifactId

1.0版-快照/版本

包装警告/包装

name spring MVC _ day 01 _ 01 _ start Maven web app/name

!-修理我将其更改为项目的网站-

urlhttp://www.example.com/url

性能

项目。建造。sourceencodingutf-8/项目。建造。信源编码

maven.compiler.source11/maven。编译器。来源

玛文。编译器。目标11/maven。编译器。目标

5.3.9/spring .版本

/属性

属国

属国

groupIdjunit/groupId

artifactIdjunit/artifactId

版本4.11/版本

范围测试/范围

/依赖关系

属国

groupIdorg.springframework/groupId

artifact id spring-context/artifact id

版本${spring.version}/version

/依赖关系

属国

groupIdorg.springframework/groupId

artifactId spring-web/artifactId

版本${spring.version}/version

/依赖关系

属国

groupIdorg.springframework/groupId

artifactId spring-web MVC/artifactId

版本${spring.version}/version

/依赖关系

属国

groupIdjavax.servlet/groupId

artifact id servlet-API/artifact id

l

t;version>2.5</version> <scope>provided</scope> </dependency> <dependency> <groupId>javax.servlet.jsp</groupId> <artifactId>jsp-api</artifactId> <version>2.0</version> <scope>provided</scope> </dependency> </dependencies> <build> <finalName>springmvc_day01_01_start</finalName> <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) --> <plugins> <plugin> <artifactId>maven-clean-plugin</artifactId> <version>3.1.0</version> </plugin> <!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging --> <plugin> <artifactId>maven-resources-plugin</artifactId> <version>3.0.2</version> </plugin> <plugin> <artifactId>maven-compiler-plugin</artifactId> <version>3.8.0</version> </plugin> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.22.1</version> </plugin> <plugin> <artifactId>maven-war-plugin</artifactId> <version>3.2.2</version> </plugin> <plugin> <artifactId>maven-install-plugin</artifactId> <version>2.5.2</version> </plugin> <plugin> <artifactId>maven-deploy-plugin</artifactId> <version>2.8.2</version> </plugin> <plugin> <groupId>org.apache.tomcat.maven</groupId> <artifactId>tomcat7-maven-plugin</artifactId> <version>2.2</version> <configuration> <port>80</port> </configuration> </plugin> </plugins> </pluginManagement> </build> </project>

2.web.xml配置指挥中心

SpringMVC是基于Servlet实现的(structs2是基于filter),有点类似于BaseServlet的抽取(BaseServlet链接),通过拦截所有路径,获取路径进行字符串处理,得到请求的路径,再调用其相应的类和方法。

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
  <display-name>Archetype Created Web Application</display-name>
  
  <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-->
  </servlet>
  
  <servlet-mapping>
    <servlet-name>dispatcherServlet</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>
</web-app>

3.springmvc配置文件

<?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"
       xmlns:mvc="http://www.springframework.org/schema/mvc"
       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
        http://www.springframework.org/schema/mvc
        https://www.springframework.org/schema/mvc/spring-mvc.xsd">
    <!--开启注解扫描-->
    <context:component-scan base-package="com.czy"></context:component-scan>
    <!--视图解析器对象-->
    <bean id="internalResourceViewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/"></property>
        <property name="suffix" value=".jsp"></property>
    </bean>
    <!--开启SpringMVC框架注解的支持-->
    <mvc:annotation-driven></mvc:annotation-driven>
</beans>

4.Controller

package com.czy.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//控制器类
@Controller
public class HelloController {
    @RequestMapping("/hello")
    public String sayHello(){
        System.out.println("Hello SpringMVC");
        return "success";  //springmvc会跳转到名为success的页面
    }
}

5.前台

xyukxfg0jo03171.png

总结

l2fq4nl2oug3172.png

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now