基本结构:
EINS、配置web.xml:
?
class="xml"> <servlet> <servlet-name>springmvc</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml,classpath*:applicationContext.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>springmvc</servlet-name> <url-pattern>*.yy</url-pattern> </servlet-mapping>
?
ZWEI、配置applicationContext.xml:
?
?
<bean id="handlerMapping" class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"></bean> <!-- 定义视图解析器ViewResolver --> <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="prefix" value="/WEB-INF/"></property> <property name="suffix" value=".jsp"></property> </bean> <!-- 路径可以指定 --> <context:component-scan base-package="./"/>
?
DREI、写两个控制类:
@Controller @Scope("prototype") public class Controller2 { @RequestMapping("/hello2.yy") public String execute(){ return "jsp/ttt"; } }
@Controller @Scope("prototype") public class MyController{ @RequestMapping("/hello.yy") public String execute(Model model){ model.addAttribute("msg","夜月"); return "jsp/hello"; } }
?
VIER、访问:
简单的测试↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓
<a href="hello2.yy">This is my JSP page. </a><br>
?
<form action="hello.yy" method="post"> <input type="submit"> </form>?
?
??(????)
?
?
?