<!--控制层-->
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. python-socket.error[10054]:对象的复制

    1.socket.error[10054],对方强制关闭了连接 在用socket.recvfrom时,若事先没有bind时, 先使用socket.sendto,socket.recvfrom 有时会出 ...

  2. 【Sass初级】开始使用Sass和Compass

    转自:http://www.w3cplus.com/preprocessor/beginner/getting-started-with-sass-and-compass.html 如果你的朋友.同事 ...

  3. mysql innodb锁简析(2)

    继续昨天的innodb锁的分析: 注:此博文参考一下地址,那里讲的也很详细.http://xm-king.iteye.com/blog/770721 mysql事务的隔离级别分为四种,隔离级别越高,数 ...

  4. 简单的聊天程序,主要用到的是Socket

    服务端: import java.io.*; import java.net.*; import java.util.*; public class ChatServer { boolean stat ...

  5. makefile实例(2)-多个文件实例

    1,源文件依赖关系 defs.h command.h buffer.h main.cpp * util.cpp * kde.cpp * * command.cpp * * display.cpp * ...

  6. DataGridView固定了列名,怎样将数据内容绑定在列上

    留心驿站 原文 其实很简单,在DataGridView上右键选择编辑列,在数据一项中找到DataPropertyName,在里面写上对应的要绑定的数据中的字段名,即可 .比如:从数据库中选择的data ...

  7. Delphi 注册文件类型 设置文件图标

        {------------------------------------------------------------------------------- @过程名: slpert -& ...

  8. GitHub使用教程及常见错误解决

    1.下载Git并安装 Git for Windows Git-1.8.4-preview20130916.exe 按照默认步骤完成安装 2.设置SSH建立计算机与Github的链接 2.1 点击 开始 ...

  9. Python编程中的反模式

    Python是时下最热门的编程语言之一了.简洁而富有表达力的语法,两三行代码往往就能解决十来行C代码才能解决的问题:丰富的标准库和第三方库,大大节约了开发时间,使它成为那些对性能没有严苛要求的开发任务 ...

  10. Treap树

    Treap树算是一种简单的优化策略,这名字大家也能猜到,树和堆的合体,其实原理比较简单,在树中维护一个"优先级“,”优先级“ 采用随机数的方法,但是”优先级“必须满足根堆的性质,当然是“大根 ...