springmvc第一个项目helloworld配置

使用maven项目


			junit
			junit
			3.8.1
			test
		
		
			javax.servlet
			javax.servlet-api
			3.1.0
			provided
		
		
			org.springframework
			spring-webmvc
			4.1.5.RELEASE
		

以下springmvc相关配置:

1.在web.xml中配置Servlet 




	Archetype Created Web Application
	
		springmvc 
		org.springframework.web.servlet.DispatcherServlet
		1
	
	 
		springmvc
		/
	


2.创建Spring MVC的xml配置文件 springmvc-servlet.xml



       
	
	
	
	
	
	     
	     
	

3.创建Controller 和相关View

package com.springmvc.zzc;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;
/**
 * 继承抽象的控制器
 * @author Administrator
 *
 */
public class HelloController extends AbstractController {

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse arg1)
			throws Exception {
		// TODO Auto-generated method stub
		String hello = (String) request.getParameter("hello"); // 接收的参数
		System.out.println("Hello:"+hello);
		
		ModelAndView modelAndView = new ModelAndView("success"); // "success"对应的jsp界面
		modelAndView.addObject("q", hello); // 传入的参数
		return modelAndView;
	}

}
hello.jsp
<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>




Insert title here


	
Hello:
success.jsp

<%@ page isELIgnored="false" language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>




Insert title here


	

${q }


最基础的springmvc配置完成



你可能感兴趣的:(springmvc,spring,mvc)