contoh addAttribute spring mvc

Belajar spring mvc : menggunakan addAttribute

Bismillah

q> Melanjutkan project sebelumnya :
https://saifiahmada.wordpress.com/2014/12/08/error-jsp-superclass-javax-servlet-http-httpservlet-pada-eclipse/

q> File jsp


<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!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=UTF-8">
<title>Testing Pang</title>
</head>
<body>

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

</body>
</html>

q> File IndexController.java


package com.saifiahmada.maven.controller;

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

@Controller
public class IndexController {

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

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

q> Hasilnya
Selection_589

Alhamdulillah

Published by

saifiahmada

Begin a big Process with a bit trying

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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