我的jsp页面没有正确显示输出

时间:2015-05-17 15:24:54

标签: jsp spring-mvc el

这些是我的课程。

WebConfig.java:
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;

@Configuration
@EnableWebMvc
@ComponentScan(basePackages="com.pluralsight")
public class WebConfig {

}

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


@Controller
public class HelloController {

@RequestMapping(value="/greeting")
public String sayHallo(Model model){
    model.addAttribute("greeting", "Good morning Dhaka");

    return "hello.jsp";
}

}

WebAppInitializer.java:


public class WebAppInitializer implements WebApplicationInitializer {

public void onStartup(ServletContext servletContext) throws ServletException      {

    WebApplicationContext context = getContext();
    servletContext.addListener(new ContextLoaderListener(context));
    ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
    dispatcher.setLoadOnStartup(1);
    dispatcher.addMapping("*.html");
}

private AnnotationConfigWebApplicationContext getContext() {
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setConfigLocation("com.pluralsight.WebConfig");

    return context;
}

}

这是jsp页面:     为hello.jsp:          

<title>hello</title>
</head>
<body>
<h2>${greeting }</h2>
</body>
</html>

但是......当我在localhost:8080 / MyPage / greeting.html上的服务器上运行它时,我得到输出为:     $ {问候}

我怎样才能解决这个问题,意思是,我想表现出“早上好达卡!”。

1 个答案:

答案 0 :(得分:1)

在jsp页面的顶部添加此<%@ page isELIgnored="false" %>