JSP page being displayed as Java Spring text

2

My JSP page is being displayed as text. I'm using Spring and Spring Security. When I open the link to my page in the browser it opens as text (All HTML appears written on the screen as if I had opened the page in the same notebook) and does not render the JSP page. p>

It's all very simple because it's a test and although I'm injecting the ClienteService class I do not actually use it.

My Controller is this:

@Controller
public class ClienteController{
    @Autowired ClienteService clienteService;

    @RequestMapping("/index")
        ModelAndView teste1(){
    return new ModelAndView("index");
}  
}

My JSP is this:

<%@ page language="java" contentType="text/html; charset=UTF-8"        pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>

<!DOCTYPE HTML>
<html lang="pt">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Teste</title>
</head>
<body>
    <div> Teste </div>
</body>
</html>  

My Spring security configuration file:

@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {

@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
    auth
        .inMemoryAuthentication()
            .withUser("admin").password("admin").roles("USER")/*Cria usuario admin*/
            .and()
            .withUser("erro").password("erro").roles("ERRO");/*Cria usuario erro*/
}

protected void configure(HttpSecurity http) throws Exception {
    http
        .authorizeRequests()
            .antMatchers("/,/home,/index").permitAll()/*Permite a todos os usuarios acessar essas paginas*/
            .antMatchers("/erro**").hasRole("ERRO")/*Permite apenas ao usuario erro acessar essaS páginaS que começam com o nome erro*/
            .antMatchers("/db/**").access("hasRole('ADMIN') and hasRole('DBA')")
            .anyRequest().authenticated()
            .and()
        .formLogin();
}

My XML Web is this, but in reality I just copied it from another application and fixed the addresses to test:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">

<context-param>
    <param-name>contextClass</param-name>
    <param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</context-param>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>br.com.solucoes.painel.PainelApplication</param-value>
</context-param>

<filter>
    <filter-name>CharacterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>CharacterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>   

<filter>
    <filter-name>springSecurityFilterChain</filter-name>
    <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

<servlet>
    <servlet-name>spring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value></param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file></welcome-file>
</welcome-file-list>

My application.properties is this:

#JSP
spring.view.prefix: /views/
spring.view.suffix: .jsp

#web
spring.mvc.date-format: yyyy-MM-dd

#porta
server.port: 9100

I do not know if Spring security needs any additional configuration. Could someone help me?

    
asked by anonymous 30.06.2015 / 04:42

1 answer

2

Well, thanks to everyone who read the question and tried to help, I discovered the problem. There were dependencies related to the JSP that were not in the Maven POM below:

<!-- for JSPs -->
    <dependency>
        <groupId>org.apache.tomcat.embed</groupId>
        <artifactId>tomcat-embed-jasper</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>jstl</artifactId>
        <scope>provided</scope>
    </dependency>
    
02.07.2015 / 02:52