zoukankan      html  css  js  c++  java
  • SpringMVC搭建

    目录结构:

    web.xml;

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.5" 
        xmlns="http://java.sun.com/xml/ns/javaee" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
        http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
      
        
        
        <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:spring_mvc/spring_app.xml</param-value>
            </init-param>
                  <load-on-startup>1</load-on-startup>
        </servlet>  
        <servlet-mapping>
            <servlet-name>DispatcherServlet</servlet-name>
            <url-pattern>*.action</url-pattern>
        </servlet-mapping>
        
    </web-app>    

    spring_app.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:mvc="http://www.springframework.org/schema/mvc"
          xmlns:context="http://www.springframework.org/schema/context"
          xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/mvc
          http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd    
          ">
        <context:component-scan base-package="spring_mvc" />
    
    </beans>

    控制层:HelloAction.java

    package spring_mvc;
    
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.Model;
    import org.springframework.web.bind.annotation.RequestMapping;
    
    //@Controller注解解析的时候看作控制器
    @Controller
    public class HelloAction {
    
        public HelloAction(){
            System.out.println("---------------------"+this.hashCode());
        }
        //hello.action的请求都交给都交由次方法处理
        @RequestMapping(value="/hello.action")
        public String Hello() throws Exception{
            System.out.println("后台输出");
            return "success.jsp";
        }
        
    }

    jap界面:

    <%@ 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>
        欢迎 啊,老不死的
    </body>
    </html>

    访问方式:

    其中hello.action即是@RequestMapping(value="/hello.action")中value的值,return返回的值即是返回的页面

  • 相关阅读:
    Windows服务器上Mysql为设置允许远程连接提示:not allowed to connect to this MySQL server
    Java中怎样遍历两个Date日期之间的每一天
    ElementUI中el-table设置指定列固定不动,不受滚动条影响
    APP测试时不可忽视搭建代理服务器抓包测试的必要性
    ctype库试运行
    django-grappelli 安装配置
    windows下django1.7 +python3.4.2搭建记录2
    windows下django1.7 +python3.4.2搭建记录1
    【2020-11-15】大心境并不能自动化解小结
    【2020-11-14】对自己责任心的煎熬考验
  • 原文地址:https://www.cnblogs.com/jiayouxiage/p/5744367.html
Copyright © 2011-2022 走看看