Redirect jsp page using Springframework

Asked

Viewed 423 times

5

Hello!

I have the following problem in redirecting the index.jsp page to the.jsp login page, in Tomcat it only appears that this page was not found, ERROR 404. If anyone can help, I’m using and studying Spring, maybe there’s something different than jsf pages.

Index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<html>
<head>
    <title>Index</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

</head>
<body>
    <h1>Aguarde...</h1>    
    <c:redirect url="login/login.jsp"/>
</body>
</html>

login.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>Tela de Login</title>
</head>
<body>
    <h1>Testando....</h1>
</body>
</html>

application-context.xml

<context:component-scan base-package="com.gervasios.sgr" />

    <mvc:annotation-driven/>

    <mvc:view-controller path="/" view-name="index"/>

    <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix" value="/WEB-INF/pages/" />
        <property name="suffix" value=".jsp" />
    </bean>

    <mvc:resources mapping="/resources/**" location="/resources/" />

web xml.

<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"
         metadata-complete="true" version="3.0">
    <display-name>sgr-application</display-name>

    <servlet>
        <servlet-name>Spring-Servlet</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>/WEB-INF/application-context.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>Spring-Servlet</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

Using spring I have to use jsp pages only ?

  • Have you ever tried to do <c:redirect url="./login.jsp"/> or <c:redirect url="login/login.xhtml"/>

  • Thanks for the reply Miguelcpjava, I answered my question with the solution.

1 answer

1

I had to delete all jsp code from my index page and leave only this snippet.

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<c:redirect url="/login"/>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.