springMVC使用注解方式进行页面跳转
<!--控制層-->
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;
?}?
?
?
}
<!--控制層調(diào)用的類-->
package cn.org.spartacus.spring;
import org.springframework.stereotype.Service;
@Service
public class Test {
public void getsys(){
?System.out.println("調(diào)入成功!");
}
?
}
<!--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?
??? ">?
??<!-- 把標(biāo)記了@Controller注解的類轉(zhuǎn)換為bean-->????
???? <context:component-scan base-package="cn.org.spartacus.spring" />?
? ?<mvc:annotation-driven />?
?
??? <!-- 定義跳轉(zhuǎn)的文件的前后綴 -->?
??? <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">?
????? <property name="prefix" value="/WEB-INF/jsp/" />? <!-- jsp存放的路徑-->
??????? <property name="suffix" value=".jsp" />? <!-- 指定跳轉(zhuǎn)的頁面為.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的調(diào)用-->
<%@ 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>
轉(zhuǎn)載于:https://www.cnblogs.com/qgc88/p/3282317.html
總結(jié)
以上是生活随笔為你收集整理的springMVC使用注解方式进行页面跳转的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【php】php的ssh2扩展的安装
- 下一篇: hanoi塔栈递归算法c语言,c++递归