[英]JSP Content is shown on browser
I am creating a spring boot application. 我正在创建一个Spring Boot应用程序。 This is just to a Hello World program.
这只是一个Hello World程序。 When I run the application, the full content of JSP page is shown.
当我运行该应用程序时,将显示JSP页面的完整内容。 Jsp page content is
jsp页面的内容是
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:f="http://java.sun.com/jsf/core" xmlns:h="http://java.sun.com/jsf/html">
<head><title>Hello world Example</title></head>
<body>
<h1>Hello ${name}, How are you?</h1>
</body>
</html>
The name variable, I am reading giving it from a controller class HelloWorldController.java . 我正在从控制器类HelloWorldController.java中读取name变量。
@Controller
public class HelloWorldController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public ModelAndView hello() {
return new ModelAndView("hello").addObject("name", "Nagendra");
}
}
I am new to spring framework and I am not getting what is the problem here. 我是spring框架的新手,但这里没有遇到什么问题。 We don't even have web.xml in spring boot application.
在春季启动应用程序中甚至没有web.xml。 Can some one help me?
有人能帮我吗? I followed http://www.technicalkeeda.com/spring/spring-boot-mvc-example to create this sample application.
我按照http://www.technicalkeeda.com/spring/spring-boot-mvc-example创建了这个示例应用程序。
Yes, it is a problem : Edit your JSP to below : 是的,这是一个问题:在下面编辑您的JSP:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html>
<head><title>Hello world Example</title></head>
<body>
<h1>Hello ${name}, How are you?</h1>
</body>
</html>
If this doesn't work, I will tell you changes in Controller side. 如果这不起作用,我将告诉您Controller端的更改。
Update 更新
Use this controller : 使用此控制器:
@Controller
public class HelloWorldController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String hello(Model model) {
model.addAttribute("name","Nagendra");
return "nameofjspwithoutextension"; // if jsp is abc.jsp then return "abc";
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.