spirng mvc
程序员文章站
2024-01-20 15:44:46
...
1.ç¼åä¸ä¸ªè¯·æ±é¡µé¢
<%@ 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>
<a href="hello">Hello</a>
</body>
</html>
2.ç¼åä¸ä¸ªæ®éçç±»ï¼POJOä½ä¸ºController
package com.spring.mvc;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
//pojoä¸ä¸ªæ®éç±» ä½ä¸º æ§å¶å¨
@Controller
public class Helloworld {
/*
* æ å°ä¸ä¸ªå«helloç请æ±ï¼åä¸ä¸ªè¯·æ±è¦å¯ä¸ï¼@RequestMapping("/hello")ä¸è½åºç°ä¸¤ä¸ª
* å¯ä»¥ä¸åç请æ±è½¬åå°åä¸ä¸ªé¡µé¢
*/
@RequestMapping("/hello")
public String hello(){
System.out.println("fds");
/*
* è¿åhelloç»DispatcherServletä½ä¸ºåç¼å转å
*/
return "hello";
}
}
3.é
ç½®ä¸ä¸ªservletæ¥è½¬å请æ±ï¼springä¸å·²ç»æä¸ä¸ªæ ¸å¿ç±»springDispatcherServletæ¥å¤çäº
<!--
é
ç½®DispatcherServlet
-->
<!-- The front controller of this Spring Web application, responsible for handling all application requests -->
<servlet>
<servlet-name>springDispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<!--
éè¦è½¬åç请æ±æ¥èªspring.mvc.xml
-->
<param-value>classpath:spring-mvc.xml</param-value>
</init-param>
<!--
web容å¨å¯å¨çæ¶åå è½½é
ç½®
-->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- Map all requests to the DispatcherServlet for handling -->
<servlet-mapping>
<servlet-name>springDispatcherServlet</servlet-name>
<!--
æ¦æªææ请æ±
-->
<url-pattern>/</url-pattern>
</servlet-mapping>
4.é
ç½®spring.mvc.ml <!--
èªå¨æ«æå
-->
<context:component-scan base-package="com.spring.mvc"></context:component-scan>
<!--
è§å¾è§£æå¨
-->
<bean id="" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/"></property>
<property name="suffix" value=".jsp"></property>
</bean>
上一篇: 反射-通过反射来调用方法