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返回的值即是返回的页面

  • 相关阅读:
    java2: HttpClient,实现登录,请求等操作,session保持
    bat使用1
    java4: 读取配置文件
    HTML+CSS学习笔记(一)
    第1章:JavaScript简介
    第2章:在HTML中使用JavaScript
    HTML+CSS学习笔记(二)
    ASP.NET防止页面刷新的方法
    上下左右无空隙不间断图片连续滚动代码
    SQL Server2005新加的功能排名函数
  • 原文地址:https://www.cnblogs.com/jiayouxiage/p/5744367.html
Copyright © 2011-2022 走看看