控制器没有重定向到我的jsp

时间:2015-11-10 18:00:28

标签: java spring jsp spring-mvc tiles

我已经阅读了与此主题相关的数小时的其他帖子。 我将解释它是怎么回事:

我访问recuperar.jsp,只需1个表单即可设置用户的电子邮件以恢复密码。它调用我的LoginController.java - 方法(processaSenha)。

在processaSenha方法中,我只是向用户发送一封电子邮件,并打开另一个JSP并设置新密码。在这里,我的重定向不起作用。我想重定向到confirmaregeracaosenha.jsp,这个页面只显示一条消息说'好吧,我们发了电子邮件"。

我为页面创建了get方法,我在我的应用程序中执行了许多其他控制器中的操作。

的LoginController:

package br.com.kolss.boxml.controller;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import br.com.kolss.boxml.dto.RegeraSenhaDTO;
import br.com.kolss.boxml.entidades.Usuario;
import br.com.kolss.boxml.service.ContatoService;
import br.com.kolss.boxml.service.LoginService;
import br.com.kolss.boxml.service.UsuarioService;
import br.com.kolss.boxml.util.Util;

@Controller
public class LoginController {

@Autowired
protected LoginService loginService;

@Autowired
protected ContatoService contatoService;

@Autowired
private UsuarioService usuarioService;

protected Logger logger = Logger.getLogger(getClass());

@RequestMapping(value="/login",method=RequestMethod.GET)
public ModelAndView login() {

    logger.debug("LoginController.login");      

    return new ModelAndView("login");
}

@RequestMapping(value="/primeiroacesso",method=RequestMethod.GET)
public ModelAndView primeiroacesso() {

    logger.debug("LoginController.primeiroacesso");

    return new ModelAndView("primeiroacesso");
}

@RequestMapping(value="/recuperar",method=RequestMethod.GET)
public ModelAndView recuperarSenha() {

    logger.debug("LoginController.recuperar");

    return new ModelAndView("recuperar");
}

@RequestMapping(value="/regeraSenha", method=RequestMethod.POST,produces={"application/json"})
public ModelAndView processaSenha(@RequestBody RegeraSenhaDTO regeraSenhaDTO, HttpServletRequest request, HttpServletResponse response) throws Exception{   

    logger.debug("LoginController.regeraSenha"); 
    StringBuffer fullURI = request.getRequestURL();
    String pathDoUriDeEnvioParaOEmail = fullURI.toString().split("/")[2];
    loginService.regeraSenhaDoUsuario(regeraSenhaDTO.getEmail(), "", pathDoUriDeEnvioParaOEmail);
    return new ModelAndView("redirect:/confirmacaoEmailSenha");     

}   

@RequestMapping(value="/confirmacaoEmailSenha",method=RequestMethod.GET)
public ModelAndView regeracao() {

    logger.debug("LoginController.confirmacaoEmailSenha");

    return new ModelAndView("confirmacaoEmailSenha");
}

@RequestMapping(value="/confirmacaoNovaSenha",method=RequestMethod.GET)
public ModelAndView confirmacaoNovaSenha() {

    logger.debug("LoginController.confirmacaoNovaSenha");

    return new ModelAndView("confirmacaoNovaSenha");
}


@RequestMapping(value="/login/salvar", method=RequestMethod.POST,produces={"application/json"})
public @ResponseBody ModelAndView salvaSenhaPrimeiroAcesso(@RequestBody RegeraSenhaDTO regeraSenhaDTO){ 

    final Usuario usuario = usuarioService.obterUsuarioPorEmail(regeraSenhaDTO.getEmail()); 
    if(regeraSenhaDTO.getNovaSenha().equals(regeraSenhaDTO.getConfirmaSenha())){
        String cryptPassword = Util.criptografarSenha(regeraSenhaDTO.getNovaSenha());
        usuario.setSenha(cryptPassword);            
        loginService.insereNovaSenha(usuario);  
    }           

    return new ModelAndView("login");

    }

}

瓦片:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE tiles-definitions PUBLIC
   "-//Apache Software Foundation//DTD Tiles Configuration 3.0//EN"
   "http://tiles.apache.org/dtds/tiles-config_3_0.dtd">
<tiles-definitions>

<definition name="defaultTemplate" template="/restrict/template/default/template.jsp">
    <put-attribute name="header" value="/restrict/template/default/header.jsp" />
    <put-attribute name="menu" value="/restrict/template/default/menu.jsp" />
    <put-attribute name="body" value="/restrict/template/default/body.jsp" />
    <put-attribute name="footer" value="/restrict/template/default/footer.jsp" />
</definition>

<definition name="homePrimeiroAcesso" template="/primeiroacesso.jsp"/>
<definition name="homeTemplate" template="/restrict/template/home/home.jsp"/>
<definition name="homeContato" template="/restrict/template/home/contato.jsp"/>
<definition name="homeLogin" template="/login.jsp"/>    
<definition name="homeRecuperaSenha" template="/restrict/template/home/recuperar.jsp"/>  
<definition name="homeNoticiaUm" template="/restrict/template/home/noticia-1.jsp"/>
<definition name="homeNoticiaDois" template="/restrict/template/home/noticia-2.jsp"/>
<definition name="homeNoticiaTres" template="/restrict/template/home/noticia-3.jsp"/>
<definition name="homeNoticiaQuatro" template="/restrict/template/home/noticia-4.jsp"/>
<definition name="homeNoticiaCinco" template="/restrict/template/home/noticia-5.jsp"/>
<definition name="homeNoticias" template="/restrict/template/home/noticias.jsp"/>
<definition name="homeConfirmacaoEmailSenha" template="/confirmaregeracaosenha.jsp"/>
<definition name="homeConfirmacaoNovaSenha" template="/confirmanovasenha.jsp"/>

<definition name="confirmacaoNovaSenha" extends="homeConfirmacaoNovaSenha"/>
<definition name="confirmacaoEmailSenha" extends="homeConfirmacaoEmailSenha"/>
<definition name="contato" extends="homeContato"/>
<definition name="primeiroacesso" extends="homePrimeiroAcesso"/>  
<definition name="home" extends="homeTemplate"/>    
<definition name="login" extends="homeLogin"/>
<definition name="recuperar" extends="homeRecuperaSenha"/>
<definition name="noticiaUm" extends="homeNoticiaUm"/>
<definition name="noticiaDois" extends="homeNoticiaDois"/>
<definition name="noticiaTres" extends="homeNoticiaTres"/>
<definition name="noticiaQuatro" extends="homeNoticiaQuatro"/>
<definition name="noticiaCinco" extends="homeNoticiaCinco"/>
<definition name="noticias" extends="homeNoticias"/>   

<definition name="organizacao" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/organizacao.jsp" />
</definition>

<definition name="cliente" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/cliente.jsp" />
</definition>  

<definition name="cadastrosusuarios" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/cadastrosusuarios.jsp" />
</definition>

<definition name="tipoxml" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/tipoxml.jsp" />
</definition>

<definition name="statusnfecte" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/statusnfecte.jsp" />
</definition>   

<definition name="auxiliaresregras" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/auxiliaresregras.jsp" />
</definition>   

<definition name="auxiliaresmenu" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/auxiliaresmenu.jsp" />
</definition>   

<definition name="configuracoesbasicas" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/configuracoesbasicas.jsp" />
</definition>   

<definition name="auxiliaresperfil" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/auxiliaresperfil.jsp" />
</definition>  

<definition name="configuracaodoemail" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/cadastros/configuracaodoemail.jsp" />
</definition> 

<definition name="consultaextrato" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/consultas/consultaextrato.jsp" />
</definition>  

<definition name="monitorxml" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/consultas/monitorxml.jsp" />
</definition> 

<definition name="monitornotas" extends="defaultTemplate">
    <put-attribute name="body" value="/restrict/view/consultas/monitornotas.jsp" />
</definition> 


</tiles-definitions>

recuperar.jsp:

&#13;
&#13;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>

		<!-- META CONFIGURATION -->
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
		<meta http-equiv="content-language" content="pt-br">
		<meta http-equiv="X-UA-Compatible" content="IE=9"/>
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta name="robots" content="index, follow" />
		<meta name="description" content="boXml é uma ferramenta desenvolvida pela Kolss especialmente para as empresas que necessitam de uma automatização em armazenamento e organização de XML." />   
		<meta name="keywords" content="boxml, xml, armazenamento, organização, sistema, kolss" />
		<!-- // -->

		<!-- OPEN GRAPH META -->
		<meta property="og:title" content="Armazenamos e organizamos seus XMLs. Faça um teste grátis!"/>
		<meta property="og:image" content="restrict/resources/images/boxml_og.png"/>
		<meta property="og:site_name" content="boXml"/>
		<meta property="og:description" content="Uma ferramenta desenvolvida especialmente para as empresas que necessitam de uma automatização em armazenamento e organização de XML."/>
		<!-- // -->	

		<!-- WEB DESIGN & DEVELOPMENT -->
		<meta name="author" content="Brício Fernandes" />
		<meta name="reply-to" content="bricioweb@gmail.com" />
		<!-- // -->

		<!-- FAVICON -->
		<link rel="shortcut icon" href="restrict/resources/images/favicon.ico" type="image/x-icon" />
		<!-- // -->

		<!-- TITLE -->
		<title>Recuperar senha | boXml - Solução em Armazenamento de XMLs</title>
		<!-- // -->

		<!-- CSS LIBRARY -->
		<link rel="stylesheet" href="restrict/resources/css/foundation/foundation.css" />
		<link rel="stylesheet" href="restrict/resources/css/icons/flaticon.css" />
		<link rel="stylesheet" href="restrict/resources/css/styles/style.css" />
		<link rel="stylesheet" href="restrict/resources/css/simptip.css" />
		<link rel="stylesheet" href="restrict/resources/css/introloader/introLoader.css" />
		<link rel="stylesheet" href="restrict/resources/css/slick.css" />

		<!-- SCRIPT LIBRARY -->
		<script src="restrict/js/jqueryNovoTemplate/jquery.js"></script>
		<!-- // -->

		<!-- MODERNIZR - FOUNDATION -->
		<script src="restrict/js/foundation/modernizr.js"></script>
		<!-- // -->	

	</head>

	<body id="login" ng-controller="RegeraSenhaController" data-ng-app="BoxApp">

		<!-- INTRO LOADER -->
		<div id="intro"></div>
		<!-- // -->

		<!-- SECTION "CONTACT" -->
		<section id="recuperar" class="section">
			<div class="row">
						<div class="small-11 small-centered medium-7 medium-centered large-5 large-centered columns">
							
							<div class="row">
								<div class="small-12 medium-12 large-12 columns text-center">
									<div class="padding-logo">
										<img src="restrict/resources/images/boxml_logomarca_invert.png" title="boXml - Solução em armazenamento de XMLs" width="133" height="35"/>
									</div>
								</div>
							</div>
						
							<form id="form-recuperar">
							
							<div class="row">
								<div class="small-12 medium-12 large-12 columns">
									<label>Informe seu e-mail:
									<input type="text" name="email" id="email"/>
									</label>
								</div>							
							</div>						
							
							<div class="row" style="padding-top:11px">						
								<div class="small-12 small-centered medium-12 medium-centered large-12 large-centered columns">																		  
								  <input ng-click="regeraSenha()" id="btn" style="width:100%" title="Clique para gerar uma senha" class="submit button expand btn-action btn-green btn-big" type="submit" value="Gerar nova senha" />
								</div>					
							</div>
							
								
						</form>		

							<div class="row">	
								<div class="small-12 medium-12 large-12 columns text-center">								
									<div class="login-footer">
										Lembrou a senha? <a href="login" title="Clique para fazer login"><b>Faça login</b></a>
									</div>
								</div>
							</div>
						
						
						</div>
					</div>
					
			

		</section>

	<!-- // -->
	<!-- SCRIPT LIBRARY -->
	<script src="restrict/js/foundation/jquery.js"></script>
	<script src="restrict/js/foundation/foundation.min.js"></script>

	<!-- BEGIN CORE ANGULARJS PLUGINS -->
	<script src="assets/global/plugins/angularjs/angular.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/angular-sanitize.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/angular-touch.min.js"
		type="text/javascript"></script>
	<script
		src="assets/global/plugins/angularjs/plugins/angular-ui-router.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/plugins/ocLazyLoad.min.js"
		type="text/javascript"></script>
	<script
		src="assets/global/plugins/angularjs/plugins/ui-bootstrap-tpls.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/ngMask.min.js"
		type="text/javascript"></script>
	<!-- END CORE ANGULARJS PLUGINS -->

	<script src="restrict/js/app.js" type="text/javascript"></script>
	<script src="restrict/js/controllers/RegeraSenhaController.js"></script>
	<script src="restrict/js/controllers/LoginController.js"></script>
	<!-- // -->


	<script>
		// FOUNDATION LOAD
		$(document).foundation();
	</script>

	</body>
	
</html>
&#13;
&#13;
&#13;

confirmaregeracaosenha.jsp

&#13;
&#13;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<!-- META CONFIGURATION -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
	<meta http-equiv="content-language" content="pt-br">
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<meta name="robots" content="index, follow" />
		<meta name="description"
			content="boXml é uma ferramenta desenvolvida pela Kolss especialmente para as empresas que necessitam de uma automatização em armazenamento e organização de XML." />
		<meta name="keywords"
			content="boxml, xml, armazenamento, organização, sistema, kolss" />
		<!-- // -->

		<!-- OPEN GRAPH META -->
		<meta property="og:title"
			content="Armazenamos e organizamos seus XMLs. Faça um teste grátis!" />
		<meta property="og:image"
			content="restrict/resources/images/boxml_og.png" />
		<meta property="og:site_name" content="boXml" />
		<meta property="og:description"
			content="Uma ferramenta desenvolvida especialmente para as empresas que necessitam de uma automatização em armazenamento e organização de XML." />
		<!-- // -->

		<!-- // -->

		<!-- FAVICON -->
		<link rel="shortcut icon" href="restrict/resources/images/favicon.ico"
			type="image/x-icon" />
		<!-- // -->

		<!-- TITLE -->
		<title>Atualizar senha | boXml - Solução em Armazenamento de
			XMLs</title> <!-- // -->

		<!-- CSS LIBRARY -->
		<link rel="stylesheet"
			href="restrict/resources/css/foundation/foundation.css" />
		<link rel="stylesheet"
			href="restrict/resources/css/icons/flaticon.css" />
		<link rel="stylesheet" href="restrict/resources/css/styles/style.css" />
		<link rel="stylesheet" href="restrict/resources/css/simptip.css" />
		<link rel="stylesheet"
			href="restrict/resources/css/introloader/introLoader.css" />
		<link rel="stylesheet" href="restrict/resources/css/slick.css" />
		<!-- // -->

		<!-- SCRIPT LIBRARY -->
		<script src="restrict/js/jqueryNovoTemplate/jquery.js"></script>
		<!-- // -->

		<!-- MODERNIZR - FOUNDATION -->
		<script src="restrict/js/foundation/modernizr.js"></script>
		<!-- // -->
</head>

<body id="login" data-ng-app="BoxApp">

	<!-- INTRO LOADER -->
	<div id="intro"></div>
	<!-- // -->

	<!-- SECTION "CONTACT" -->
	<section id="login" class="section">
	<div class="row">
		<div
			class="small-11 small-centered medium-7 medium-centered large-5 large-centered columns">

			<div class="row">
				<div class="small-12 medium-12 large-12 columns text-center">
					<div class="padding-logo">
						<img src="restrict/resources/images/boxml_logomarca_invert.png"
							title="boXml - Solução em armazenamento de XMLs" width="133"
							height="35" />
					</div>
				</div>
			</div>

			<form id="formLogin" method="POST" action=""
				class="ng-pristine ng-valid" name="formLogin" novalidate>

				<div class="row">
					<div class="small-12 medium-12 large-12 columns">

						<label><center>Um email com as informações
								necessárias para regeração da senha da sua conta foi enviado
								para a conta de e-mail atrelada a aplicação.</center></label> 
						<div id="footer" class="footer" align="center"></div>
					</div>
				</div>
			</form>

			<div class="row">
				<div class="small-12 medium-12 large-12 columns text-center">
					<div class="login-footer clearfix">
						<span class="left"> <a href="recuperar"
							title="Clique para recuperar sua senha"><b>Esqueceu a
									senha?</b></a>
						</span>
						<div class="partner right">
							<ul>
								<li><a href="https://www.geotrust.com/" target="_blank"
									title="Secured by GeoTrust"><img
										src="restrict/resources/images/geotrust.png" width="151"
										height="37" /></a></li>
								<li><a href="https://aws.amazon.com/pt/" target="_blank"
									title="Amazon Web services"><img
										src="restrict/resources/images/amazon.png" width="126"
										height="47" /></a></li>
							</ul>
						</div>
					</div>
				</div>
			</div>

		</div>
	</div>



	</section>


	<!-- SCRIPT LIBRARY -->
	<script src="restrict/js/foundation/jquery.js"></script>
	<script src="restrict/js/foundation/foundation.min.js"></script>

	<!-- BEGIN CORE ANGULARJS PLUGINS -->
	<script src="assets/global/plugins/angularjs/angular.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/angular-sanitize.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/angular-touch.min.js"
		type="text/javascript"></script>
	<script
		src="assets/global/plugins/angularjs/plugins/angular-ui-router.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/plugins/ocLazyLoad.min.js"
		type="text/javascript"></script>
	<script
		src="assets/global/plugins/angularjs/plugins/ui-bootstrap-tpls.min.js"
		type="text/javascript"></script>
	<script src="assets/global/plugins/angularjs/ngMask.min.js"
		type="text/javascript"></script>
	<!-- END CORE ANGULARJS PLUGINS -->

	<script src="restrict/js/app.js" type="text/javascript"></script>

	<!-- // -->

	<script>
		// FOUNDATION LOAD
		$(document).foundation();  
		</script>

</body>

</html>
&#13;
&#13;
&#13;

调度-servlet.xml中:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:p="http://www.springframework.org/schema/p"
   xmlns:aop="http://www.springframework.org/schema/aop"
   xmlns:tx="http://www.springframework.org/schema/tx"
   xmlns:context="http://www.springframework.org/schema/context"
   xmlns:mvc="http://www.springframework.org/schema/mvc"
   xsi:schemaLocation="http://www.springframework.org/schema/beans     http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
   http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
   http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
   http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
   http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd">

<!--
<bean  class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <property name="prefix">
        <value>/</value>
    </property>
    <property name="suffix">
        <value>.jsp</value>
    </property>
</bean>-->

<bean id="viewResolver"  
    class="org.springframework.web.servlet.view.UrlBasedViewResolver">  
    <property name="viewClass">  
        <value>  
            org.springframework.web.servlet.view.tiles3.TilesView  
        </value>  
    </property>  
</bean>     
<bean id="tilesConfigurer"  
       class="org.springframework.web.servlet.view.tiles3.TilesConfigurer">  
    <property name="definitions">  
        <list>  
            <value>/WEB-INF/tiles.xml</value>  
        </list>  
    </property>  
</bean>  

截图:

http://imgur.com/a/4Mffr

提前致谢

1 个答案:

答案 0 :(得分:1)

一种可能的解决方案是将方法“processaSenha”的返回类型更改为String并返回“redirect:/ url / to / go”。