contoh addAttribute spring mvc

Belajar spring mvc : menggunakan addAttribute


q> Melanjutkan project sebelumnya :

q> File jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Testing Pang</title>

<h1>Selamat datang mas ${welcome}</h1>


q> File

package com.saifiahmada.maven.controller;

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

public class IndexController {

public String index(){
return "/WEB-INF/jsp/index.jsp";

public String testing(ModelMap model) {
String nama = "Saifi Ahmada";
model.addAttribute("welcome", nama);
return "/WEB-INF/jsp/testing.jsp";

q> Hasilnya



Published by


Begin a big Process with a bit trying

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s