No dobra, powoli gdzieś dochodzimy.
- Kwestia estetyki ale nie przyjmuj w kontrolerze obiektu Model, a zamiast tego z kontrolera zwracaj
ModelAndView
do którego wrzucisz dane. To trochę bardziej eleganckie rozwiązanie.
- Brakuje ci
http://
w tym URLu i html zwyczajnie go nie ładuje. Twój problem to nieznajomość htmla a robisz tu temat i Javie, Springu i jstl ;)
edit: no to pokaż teraz jaki html ci się wygenerował na stronie.
- Dzięki, zapamiętam na przyszłość.
- Jest dodany, niestety nadal nic.
Wydaje mi się, że problem tkwi w przekazywaniu zmiennej do widoku. Nieznajomość htmla? Nie mówię nie, znam podstawy, http://
był już dodany przed ostatnim postem.
Wrzucam jeszcze raz poprawiony kod.
Controller:
@Controller
public class HomeController {
private static final Logger logger = LoggerFactory.getLogger(HomeController.class);
public String imageUrl;
/**
* Simply selects the home view to render by returning its name.
*
* @throws IOException
*/
@RequestMapping(value = "/{instagramImage}", method = RequestMethod.GET)
public String home(Locale locale, Model model, @PathVariable String instagramImage) throws IOException {
logger.info("Welcome home! The client locale is {}.", locale);
logger.info(imageUrl);
Date date = new Date();
DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale);
String formattedDate = dateFormat.format(date);
imageUrl = "http://www.w3schools.com/images/w3schools_green.jpg";
model.addAttribute("imageUrl");
model.addAttribute("serverTime", formattedDate);
return "home";
}
}
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page session="false" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1>
Hello world!
</h1>
<P> The time on the server is ${serverTime}. </P>
This page receives the values you specified, and creates a URL that contains
them.
<p />
<img src="${imageUrl}" alt="W3Schools.com" style="width:104px;height:142px;">
</body>
</html>