<!--控制层-->
package cn.org.spartacus.spring;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("index")
public class testController {
  @Autowired 
     private Test test; 
 
 @RequestMapping("helloWorld")
   public String helloWorld() { 
  test.getsys();
         return "success";
      
    }

public Test getTest() {
  return test;
 }

public void setTest(Test test) {
  this.test = test;
 } 
 
 
}

<!--控制层调用的类-->
package cn.org.spartacus.spring;

import org.springframework.stereotype.Service;

@Service
public class Test {
public void getsys(){
 System.out.println("调入成功!");
}
 
}

<!--applicationContext.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:p="http://www.springframework.org/schema/p"
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-3.0.xsd 
    http://www.springframework.org/schema/context 
    http://www.springframework.org/schema/context/spring-context-3.0.xsd 
    http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd 
    "> 
  <!-- 把标记了@Controller注解的类转换为bean-->    
     <context:component-scan base-package="cn.org.spartacus.spring" /> 
   <mvc:annotation-driven /> 
 
    <!-- 定义跳转的文件的前后缀 --> 
    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> 
      <property name="prefix" value="/WEB-INF/jsp/" />  <!-- jsp存放的路径-->
        <property name="suffix" value=".jsp" />  <!-- 指定跳转的页面为.jsp格式 -->
    </bean> 
</beans>

<!--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">
  <display-name></display-name> 
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
 
  <servlet>
  <servlet-name>dispather</servlet-name>
  <servlet-class>
   org.springframework.web.servlet.DispatcherServlet
  </servlet-class>
  <init-param>
   <param-name>contextConfigLocation</param-name>
   <param-value>/WEB-INF/applicationContext.xml</param-value>
  </init-param>
  <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
  <servlet-name>dispather</servlet-name>
  <url-pattern>*.hml</url-pattern>
 </servlet-mapping>
 
  <!---中文乱码过滤器-->
            <filter>
            <filter-name>encodingFilter</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>encodingFilter</filter-name>
           <url-pattern>*.hml</url-pattern>
            </filter-mapping> 
</web-app>

<!--jsp的调用-->
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!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>
<form action="app/index/helloWorld" method="post">
<input type="submit" value="提交" />
</form>
</body>
</html>

springMVC使用注解方式进行页面跳转的更多相关文章

  1. Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法

    Spring MVC 中采用注解方式 Action中跳转到另一个Action的写法 在Action中方法的返回值都是字符串行,一般情况是返回某个JSP,如: return "xx" ...

  2. SpringMVC 05: SpringMVC中携带数据的页面跳转

    SpringMVC默认的参数对象 SpringMVC默认的参数对象是指,不用再另行创建,相当于SpringMVC内置对象,可以直接声明并使用 默认的参数对象有:HttpServletRequest,H ...

  3. SpringMVC的注解方式

    mvc-servlet.xml <?xml version="1.0" encoding="UTF-8"?> <beans xmlns=&qu ...

  4. SpringMVC的注解方式配置

    SpringMVC支持使用注解方式配置,比配置文件方式更加灵活易用,是SpringMVC使用的主流模式. 1.在配置文件中开启SpringMVC的注解 <!-- 开启包扫描 --> < ...

  5. springmvc 用注解方式添加事务不生效解决方法

    springmvc 事务注册有很多种方法,在此我只mark 用注解方式添加transaction不生效的解决办法. springmvc 注解方法添加事务步骤: 1.在 spring的 root-con ...

  6. SpringMVC基于注解方式的quartz

    项目框架: SpringMVC.MyBatis.JSP 1. 首先配置spring.xml文件 <?xml version="1.0" encoding="UTF- ...

  7. 基于 Storyboard 多种方式的页面跳转、参数传递

    原文 通过按钮关联跳转 选中 Button ,然后点击 action 右边拖拽到 第二个页面 选择 "Show"即可完成跳转关联. 定义页面间 segue Id,通过代码触发跳转 ...

  8. springmvc不通过controller进行页面跳转

    1.controller 继承WebMvcConfigureAdapter 然后使用ViewControllerRegistry  来进行跳转

  9. js方式的页面跳转

    window.location.href="login.html";   (直接function里面执行 跳转)

随机推荐

  1. 纯CSS3大转盘抽奖(响应式、可配置)

    源于前段时候微信小程序最初火爆公测时段,把以前用 Canvas 实现的大转盘抽奖移植成微信小程序,无奈当时小程序对 Canvas 支持不够完善,只好降低用 CSS3 实现.虽然比不上 Canvas 绘 ...

  2. Java 动态眨眼 EyesJPanel (整理)

    /** * Java 动态眨眼 EyesJPanel (整理) * * 2016-1-2 深圳 南山平山村 曾剑锋 * 注意事项: * 1.本程序为java程序,同时感谢您花费宝贵的时间来阅读本文档: ...

  3. 浅析extendedLayout, automaticallyAdjustsScrollViewInsets, extendedLayoutIncludesOpaqueBars

    参考文章: http://stackoverflow.com/questions/18798792/explaining-difference-between-automaticallyadjusts ...

  4. Python内置数据类型之List篇

    List的定义: li = ["one" , "two" , "three" , "four"] List是一个有序的集 ...

  5. 聊聊Dataguard的三种保护模式实验(上)

    Data Guard是Oracle高可用性HA的重要解决方案.针对不同的系统保护需求,DG提供了三种不同类型的保护模式(Protection Mode),分别为:最大保护(Maximum Protec ...

  6. 基于CentOS与VmwareStation10搭建Oracle11G RAC 64集群环境:4.安装Oracle RAC FAQ-4.2.Oracleasm Createdisk ASM磁盘失败:Instantiating disk: failed

    1.错误信息:Instantiating disk: failed [root@linuxrac1 /]# /usr/sbin/oracleasm createdisk OCR_VOTE /dev/s ...

  7. Shell教程4-Shell替换

    如果表达式中包含特殊字符,Shell 将会进行替换.例如,在双引号中使用变量就是一种替换,转义字符也是一种替换. 举个例子: 复制纯文本新窗口   #!/bin/bash a=10 echo -e & ...

  8. UIScrollView 不能滚动的问题

    uiscrollview是开发sdk自带的控件, 在使用的时候,发现滚动不了, 最常山见的原因是 contentSize 这个属性,比uiscrollview的frame要小...所以无需滚动,自然就 ...

  9. linux下动态库编译的依赖问题

    这里主要是想试验一下,对一个具有多层嵌套的动态库进行编译时,是否要把最底层的库也包含进来的问题,结论是:只要直接依赖的库名称,不需要最底层库名称. 一,目录结构ZZZ├── add│   ├── ad ...

  10. Java之--Java语言基础组成(关键字、标识符、注释、常量和变量、运算符)

    Java语言基础组成-关键字.标识符.注释.常量和变量.运算符 Java语言由8个模块构成,分别为:1.关键字:2.标识符(包名.类名.接口名.常量名.变量名等):3.注释:4.常量和变量:5.运算符 ...