SpringMVC学习之基础篇

浏览器地址栏请求:http:localhost:8080/springmvc_hello/hello?username=kk

web.xml:



	
		hello
		org.springframework.web.servlet.DispatcherServlet
		1
	
	
		hello
		/
	
	
	
		CharacterFilter
		org.springframework.web.filter.CharacterEncodingFilter
		
			encoding
			UTF-8
		
	
	
		CharacterFilter
		/*
	

 

hello-servlet.xml:



	
	
	
	
	
	
	
	
		
		
		
	
	
	
	
		
	
	
	
		
			
				error
			
		
	

 

HelloController.java:

package zttc.itat.controller;


import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class HelloController {
	
	//RequestMapping表示用那个url来对应
	@RequestMapping({"/hello","/"})
	public String hello(String username,Model model) {
		System.out.println("hello");
		model.addAttribute("username", username);
		//此时用那个作为key?它默认是使用对象的类型作为key-->model.addAttribute("string",username)
		//model.addAttribute(new User());-->addAtt("user",new User());
		model.addAttribute(username);
		System.out.println(username);
		return "hello";
	}
	
	@RequestMapping("/welcome")
	public String welcome() {
		return "welcome";
	}
	
}

 

hello.jsp:

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




Insert title here


hello ${username }!!

${string }

 

 

 

你可能感兴趣的:(SpringMVC)