1、applicationContext配置
<?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: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/context http://www.springframework.org/schema/context/spring-context-3.0.xsd" > <context:component-scan base-package="com.jt"/> <!-- 视图分解解析器 --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <!-- 这是前缀 --> <property name="prefix" value="/WEB-INF/jsp/"></property> <!-- 这是后缀 --> <property name="suffix" value=".jsp"></property> <!-- 在spring的控制器中,返回的是一个字符串,那么请求的路径则是,前缀+返回字符串+后缀 --> </bean> </beans>
2、控制器代码
package com.jt; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping(value="/FirstControl") public class HelloControl { @RequestMapping("/default") public String mydefault(){ return "default"; } }
3、界面代码
<%@ 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> default </body> </html>
4、目录结构
5、显示效果