session with spring and iframe - spring

I work with spring and jsp ( which include iframe)
I have problem with session
I have the login page ( index.jsp) and I have other page ( menu.jsp) which include iframe
I want when the session is expired to redirect from menu.jsp to index.jsp
this is my index.jsp :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<!-- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> -->
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>index</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link rel="stylesheet" type="text/css" href="/Test/theme/login.css">
<!--[if IE 6]>
<link href="default_ie6.css" rel="stylesheet" type="text/css" />
<![endif]-->
</head>
<body>
<div id="wrapper">
<div id="page">
<div id="content">
<div id="content_space">
<form name='f' action="<c:url value='j_spring_security_check' />" method="POST">
<c:if test="${param.error == 1}">
<h3 style="font-size:20; color:#FF1C19;">error.</h3>
</c:if>
<table dir="ltr">
<tbody>
<tr>
<td width="100%">
<table align="left" width="100%" dir="ltr" style="padding-top: 35px;">
<tbody><tr>
<td width="10"></td>
<td><input name="j_username" type="text" value=""></td>
<td width="10"></td>
<td style="color: #000000" align="right">username</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td width="100%">
<span id="_58_passwordCapsLockSpan" style="display: none;">Caps Lock is on.</span><table align="left" dir="ltr" width="100%">
<tbody><tr>
<td width="10"></td>
<td><input name="j_password" type="password" value=""></td>
<td width="10"></td>
<td style="color: #000000" align="right">login</td>
</tr>
</tbody></table>
</td>
</tr>
<tr>
<td>
<table align="left" dir="ltr" style="padding-left: 15px;">
<tbody><tr>
<td><input type="submit" class="signinAR" value=""></td>
<td width="10"></td>
</tr>
</tbody></table>
</td>
</tr>
</tbody></table>
</form>
</div>
</div>
<div id="sidebar">
<p></p>
</div>
</div>
</div>
</body>
</html>
and this is my menu.jsp
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%#page import="org.springframework.security.core.userdetails.UserDetails"%>
<%#page import="org.springframework.security.core.context.SecurityContextHolder"%>
<%
String contextPath = request.getContextPath();
Boolean enbaleSMenu = false;
if(request.isUserInRole("ADMIN")){
enbaleSMenu=true;
}
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
if(username.equals("anonymousUser")){
response.sendRedirect("/Test/index.htm");
parent.reLoadPage();
}
%>
<html>
<head>
<title>menu</title>
<link rel="stylesheet" type="text/css" href="/Test/theme/default.css">
<script type="text/javascript"
src="<c:url value='/extjs/jquery-latest.min.js'/>"></script>
<script type="text/javascript"
src="<c:url value='/extjs/main.js'/>"></script>
<script>
function loadIframe(iframeName, url) {
var $iframe = $('#' + iframeName);
if ( $iframe.length ) {
$iframe.attr('src',url);
return false;
}
return true;
}
function reLoadPage(){
location.replace("/Test/index.htm");
location.reload();
}
// hidding menu
var hiddenSMenu=<%=enbaleSMenu%>;
function showMenu()
{
if(hiddenSMenu)
{
document.getElementById("idSmenu").children[2].style.display="none";
loadIframe('cmpframe', '/Test/administration/Validation.htm');
}
else
{
document.getElementById("idSmenu").children[0].style.display="none";
document.getElementById("idSmenu").children[1].style.display="none";
loadIframe('cmpframe', '/Test/citizen/Request.htm');
}
}
</script>
<style type="text/css">
label.myBold
{
font-weight: bold;
text-decoration: none;
color: red;
}
.my-fieldset {
background: #F1F3FB,
border: 1px solid red
}
.my-fieldset .x-fieldset-header {
color: red
}
</style>
</head>
<body dir="rtl" onload="showMenu()" >
<script>
<%#taglib uri="http://www.springframework.org/tags" prefix="spring"%>
</script>
<a href="<c:url value="../j_spring_security_logout" />" > ????</a>
<div id="wrapper">
<div id="header">
<div id="logo_left">
<p>
<img src="/Test/theme/images/Taif_logo.png">
</p>
</div>
<div id="logo">
<h1><img src="/Test/theme/images/MIS_logo.png"></h1>
</div>
</div>
<div id="page">
<div id='cssmenu'>
<ul>
<li style="display: none;><span>Home</span></li>
<li><span><spring:message code="label.titleProjet"/></span>
<ul id="idSmenu">
<li class="current"><spring:message code="label.consult"/></li>
<li class="current"><spring:message code="label.validate"/></li>
<li class="current"><spring:message code="label.Request"/></li>
</ul>
</li>
</li>
</ul>
</div>
<div id = "divFrame" >
<iframe id="cmpframe" name="myframe" width="84%" height="100%" >
</iframe></div>
</div>
</div>
</body>
</html>
this is the code whcih should redirect from menu.jsp to index.jsp when the session is expired :
Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String username = "";
if (principal instanceof UserDetails) {
username = ((UserDetails)principal).getUsername();
} else {
username = principal.toString();
}
if(username.equals("anonymousUser")){
response.sendRedirect("/Test/index.htm");
parent.reLoadPage();
}
but with this code I have also the same problem
Updated :
this is my error when I test this code :
parent cannot be resolved
39: }
40: if(username.equals("anonymousUser")){
41: response.sendRedirect("/Test/index.htm");
42: parent.reLoadPage();
43: }
44:
45:
I didn't know how can I declare parent

Related

My app.js vue file is doing nothing whatsoever

Here is my blade file. The v-models are not reactive, and the button does nothing when clicked. I am getting no errors from vue at all. I tried running an alert() function in the mounted property, it worked fine. But nothing else works? What am I doing wrong?
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flower Company</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link href="/css/style.css" rel="stylesheet">
<link href="/css/fontawesome-pro.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<meta name="csrf-token" content="{{csrf_token()}}">
<!------ Include the above in your HEAD tag ---------->
</head>
<body>
<div id="app"></div>
<table class="table">
<form action="#" #submit.prevent="validateData" #keydown="errors.clear($event.target.name)">
<tbody>
<tr></tr>
<tr>
<td>
<input type="text" name="name" v-model="model.name" class="input_title_desc" required placeholder="Name"><!-- End td 1 -->
</td>
<td>
<input type="text" name="email" v-model="model.email" class="input_title_desc" id="email" placeholder="Email">
<!-- End td 2 -->
</td>
<td>
<input type="text" name="phone" v-model="model.phone" class="input_title_desc" id="phone" required placeholder="Phone">
<!-- End td 3 -->
</td>
</tr>
<tr></tr>
<tr>
<td colspan="3">
<input type="text" name="address" v-model="model.address"
class="input_description" placeholder="Address">
<button type="button" class="btn_add_fin" #click="validateData">
<i class="far fa-user-plus fa-2x"></i>
</button>
</td>
</tr>
<tr>
<td colspan="3"></td>
</tr>
</tbody>
</form>
</table>
</div>
<script src="{{asset('js/app.js')}}"></script>
</body>
</html>
And then my app.js file:
import Vue from 'vue'
window.Vue = require('vue');
window.axios = require('axios');
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
/**
* Next we will register the CSRF Token as a common header with Axios so that
* all outgoing HTTP requests automatically have it attached. This is just
* a simple convenience so we don't have to attach every token manually.
*/
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
window.axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
} else {
console.error('CSRF token not found: https://laravel.com/docs/csrf#csrf-x-csrf-token');
}
class Errors
{
constructor()
{
this.errors = {};
}
get(field)
{
if (this.errors[field]) {
return this.errors[field][0];
}
}
record(errors)
{
this.errors = errors;
}
clear(field)
{
delete this.errors[field];
}
has(field)
{
return this.errors.hasOwnProperty(field);
}
any()
{
return Object.keys(this.errors).length > 0;
}
}
new Vue({
el: '#app',
data: {
errors: new Errors(),
model: {
name: '',
email: '',
phone: '',
address: ''
}
},
methods: {
validateData: function() {
axios.post('/validate-data', this.$data.model)
.then((response) => {
console.log(response);
var date = $('#email').val();
var description = document.querySelector('.input_description').value;
var title = document.querySelector('.input_title_desc').value;
var action = $('#phone').val();
var class_li =['list_shopping list_dsp_none','list_work list_dsp_none','list_sport list_dsp_none','list_music list_dsp_none'];
var cont = '<div class="col_md_1_list"><p>'+action+'</p></div><div class="col_md_2_list"><h4>'+title+'</h4><p>'+description+'</p></div><div class="col_md_3_list"><div class="cont_text_date"><p>'+date+'</p></div><div class="cont_btns_options"><i class="fas fa-mobile-alt fa-2x" style="color: #6d696f;"></i><ul><li></i></li></ul></div></div>';
var li = document.createElement('li');
li.className = class_li[select_opt]+" li_num_"+contador;
li.innerHTML = cont;
document.querySelectorAll('.cont_princ_lists > ul')[0].appendChild(li);
setTimeout(function(){ document.querySelector('.li_num_'+contador).style.display = "block";
},100);
setTimeout(function(){
document.querySelector('.li_num_'+contador).className = "list_dsp_true "+class_li[select_opt]+" li_num_"+contador;
contador++;
},200);
$('#email').val('');
$('.input_description').val('');
$('.input_title_desc').val('');
$('#phone').val('');
})
.catch(error => {
});
}
}
});
I don't understand why this is not working?
Your contents are outside of div which id is app for Vue.
look at this <div id="app"></div>
Please make sure all of your elements which need to be with Vue is inside of your app div.
correction:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Flower Company</title>
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<link href="/css/style.css" rel="stylesheet">
<link href="/css/fontawesome-pro.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
<meta name="csrf-token" content="{{csrf_token()}}">
<!------ Include the above in your HEAD tag ---------->
</head>
<body>
<div id="app">
<table class="table">
<form action="#" #submit.prevent="validateData" #keydown="errors.clear($event.target.name)">
<tbody><tr>
</tr>
<tr>
<td>
<input type="text" name="name" v-model="model.name" class="input_title_desc" required placeholder="Name"><!-- End td 1 -->
</td>
<td>
<input type="text" name="email" v-model="model.email" class="input_title_desc" id="email" placeholder="Email">
<!-- End td 2 -->
</td>
<td>
<input type="text" name="phone" v-model="model.phone" class="input_title_desc" id="phone" required placeholder="Phone">
<!-- End td 3 -->
</td>
</tr>
<tr>
</tr>
<tr>
<td colspan="3">
<input type="text" name="address" v-model="model.address" class="input_description" placeholder="Address">
<button type="button" class="btn_add_fin" #click="validateData"><i class="far fa-user-plus fa-2x"></i></button>
</td>
</tr>
<tr>
<td colspan="3">
</td>
</tr>
</tbody>
</form>
</table>
</div>
<script src="{{asset('js/app.js')}}"></script>
</body>
</html>

SpringMVC - Pass object created in POST to the get method (show results of search on the same page)

I'm a bit of a newbie in JEE and I'm trying to make a search page in my WebService, I use SpringMVC and I can search and get results in my controller (when I call a POST on my view) but I can't pass the object containing the results to the GET method of my controller.
Here are my controller methods :
#RequestMapping(value = "/search", method = RequestMethod.GET)
public String searchPage(ModelMap model) {
String movie = null;
model.addAttribute("movie", movie);
return "search";
}
#RequestMapping(value = "/search", method=RequestMethod.POST)
public String searchMovie(#RequestParam String movie, ModelMap model) throws IOException {
movieService.setMovieName(movie);
BaseResultsPage<BaseMovie> searchResults = movieService.movieSearch();
System.out.println("search :" +searchResults.page);
model.addAttribute("search_results", searchResults);
return "search";
}
I want to access the object in the following view :
<%# page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="description" content=""/>
<meta name="author" content=""/>
<link rel="icon" href="../../favicon.ico"/>
<title>Sign up</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">
<!-- Custom styles for this template-->
<link rel="stylesheet" href="${pageContext.request.contextPath}/static/css/app.css"/>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
</head>
<body>
<header>
<h3>Search Movies</h3>
</header>
<c:url var="loginUrl" value="/login" />
<form action="${searchUrl}" method="post">
<div class="group">
<input type="text" id="movie" name="movie"/>
<span class="highlight"></span>
<span class="bar"></span>
<label>Movie Title</label>
</div>
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}" />
<div class="form-actions">
<input class="btn btn-primary" type="submit" value="Search"/>
</div>
</form>
<div>
<c:if test="${seach_results == null}">
<table style="border-collapse: collapse;" border="1" class="showResults">
<tr>
<td colspan="7">No Results found</td>
</tr>
</table>
</c:if>
<c:if test="${seach_results != null}">
<table style="border-collapse: collapse;" border="1" class="showResults">
<tr>
<td colspan="7">Result found</td>
</tr>
</table>
</c:if>
</body>
<script>
$(document).ready(function() {
$('input').blur(function () {
var $this = $(this);
if ($this.val())
$this.addClass('used');
else
$this.removeClass('used');
});
});
</script>
</html>
I want to be able to access searchResults inside the view (and detect if its empty).
Thx for your help !
You need to use Redirect/AddFLashAttributes, you can check examples at https://www.concretepage.com/spring/spring-mvc/spring-mvc-redirectview-example-add-fetch-flash-attributes-redirectattributes-model-requestcontextutils or http://www.logicbig.com/tutorials/spring-framework/spring-web-mvc/redirect-attributes/ or http://viralpatel.net/blogs/spring-mvc-flash-attribute-example/

Vue.js and Laravel integration issue

Ran into a bit of a problem with combining Laravel and Vue.js to populate a table.
Essentially, I was trying to use the v-repeat property in combination with a http:get request using the vue-resources extension. The problem is that no values appear to be getting passed through by Vue - I simply get the {{first_name}} and {{email_address}} in brackets.
I can confirm that the API method that is called by the http:get request is in fact spitting out data (manually accessing the URL in the browser reveals data).
Here is the code in the routes.php file that is responsible for outputting the data:
get('api/v1_users',function()
{
return App\User::all()->toJson();
});
And here is what it spits out in the browser:
[{"email_address":"test123#gmail.com,"first_name":"John","password":"test123"}]
The Chrome console displays no errors nor warnings.
Here is my blade file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Navbar Template for Bootstrap</title>
<!-- Bootstrap core CSS -->
<link media="all" type="text/css" rel="stylesheet" href="{{ URL::asset('css/bootstrap.min.css') }}">
<!-- Custom styles for this template -->
{!! Html::style('css/navbar.css') !!}
</head>
<body>
<div class="container">
<!-- Static navbar -->
<nav class="navbar navbar-default">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">User Password Operations</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
<li class="inactive">Reset New User</li>
<li class="inactive">Pending Users</li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</nav>
<!-- Main component for a primary marketing message or call to action -->
<div class="jumbotron">
<h1>Pending 1.0 Users</h1>
<p>A list of 1.0 users that have a change!me password as a result of this tool, and are awaiting password change.</p>
</div>
<table class="table table-bordered">
<tr>
<td>
<b>Name</b>
</td>
<td>
<b>Email</b>
</td>
<td>
<b>Select</b>
</td>
</tr>
<div id = "user">
<tr v-repeat = "user: v1_user">
<td>
#{{ first_name }}
</td>
<td>
#{{ email_address }}
</td>
<td>
<button type="button" class="btn btn-success">Revert Password To Original</button>
</td>
</tr>
</div>
</table>
<div class="jumbotron">
<h1>Pending 2.0 Users</h1>
<p>A list of 2.0 users that have a change!me password as a result of this tool, and are awaiting password change.</p>
</div>
<table class="table table-bordered">
<tr>
<td>
<b>Name</b>
</td>
<td>
<b>Email</b>
</td>
<td>
<b>Select</b>
</td>
</tr>
<div>
<tr v-repeat = "user: v1_user">
<td>
#{{user.first_name}}
</td>
<td>
#{{user.email_address}}
</td>
<td>
<button type="button" class="btn btn-success" v-on= "click: onClick">Revert Password To Original</button>
</td>
</tr>
</div>
</table>
</div> <!-- /container -->
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<!-- Vue.js file REP -->
<script src="/js/vue.js"></script>
<script src="/js/vue-resource.min.js"></script>
<!-- Main Vue file-->
<script src="/js/main.js"></script>
</body>
</html>
Here is the accompanying javascript file with the Vue.js code: (main.js)
new Vue({
el: "#user",
data:
{
v1_user:[],
},
ready : function()
{
this.fetchV1IntermediaryUsers();
},
methods:
{
fetchV1IntermediaryUsers: function() {
this.$http.get('/api/v1_users',function(v1users) {
this.$set('v1_user',v1users);
});
}
}
});
You have multiple DIV's with the same ID's. ID's in HTML must be unique. When you start a VUE instance you bind it to an element, in this case which is in your code twice. Remove the ID's and add an ID to the <Body> tag, then check your code.

Jquery not working for me

I have followed different solution here in stacj overflow with regards to coinslider not moving. So here's mine. It seems that I dont know how to make it move.
here's my code.
Thanks.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="Index.aspx.cs" Inherits="LeavemanagementFinal.Index" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CrossXTrain - Home</title>
<link href="css/master.css" rel="stylesheet" />
<link href="css/coin-slider-styles.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/jquery-1.7.2.js"></script>
<script type="text/javascript" src="js/coin-slider.min.js"></script>
<%--<style type="text/css">
.frame
{
font:12px arial;
width:200px;
height:200px;
border:none;
overflow:hidden;
border:1px solid black;
padding:5;
}
</style>
<script language="javascript">
i = 0
var speed = 1
function scroll() {
i = i + speed
var div = document.getElementById("news")
div.scrollTop = i
if (i > div.scrollHeight - 160) { i = 0 }
t1 = setTimeout("scroll()", 10)
}
</script>--%>
</head>
<body onload="scroll()">
<div class="divpage">
<img src="images/header2.png">
<div class="divmenu">
<a class="FontStaticMenuItemStyle" href="index.aspx"> Home</a>
<a class="FontStaticMenuItemStyle" href="leavemanagementlogin.aspx"> Leave Management</a>
<a class="FontStaticMenuItemStyle" href="news.aspx"> News</a>
<a class="FontStaticMenuItemStyle" href=""> Articles</a>
<a class="FontStaticMenuItemStyle" href="aboutus.aspx"> About Us</a>
<a class="FontStaticMenuItemStyle" href="contactus.aspx"> Contact Us</a>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#news').news();
});
</script>
<div class="mainbanner" id="news" >
<img src="images/BUBLES.jpg" />
<img src="images/CrossXtrain.jpg"/>
<img src="images/CrossXtrain3.jpg"/>
<img src="images/CrossXtrain4.jpg"/>
<img src="images/CrossXtrain5.jpg"/>
<img src="images/CrossXtrain6.jpg"/>
<img src="images/CrossXtrain7.jpg"/>
<img src="images/CrossXtrain8.jpg"/>
<img src="images/CrossXtrain9.jpg"/>
</div>
<div class="clear">&nbsp</div>
<div class="mainadfooter">
<input type="image" class="secondinput" src="images/BUBLES.jpg"/>
<input type="image" class="thirdinput" src="images/HCS.jpg" onclick="javascript: window.location.href = 'http://www.healthcaresynergy.com/'"/>
<input type="image" class="thirdinput" src="images/fusionplus.png" onclick="javascript: window.location.href = 'http://sync.fusionpl.us//'"/>
<input type="image" class="thirdinput" src="images/DoubleRule_Logo#2x.png" onclick="javascript: window.location.href = 'http://www.doublerule.com/'"/>
</div>
<div class="clear">&nbsp</div>
</div>
<div class="clear">&nbsp</div>
<div class="footer"><p>Copyright © 2014. CrossXTrain Company Inc. All rights reserved. | Leave Management System - ISD (Php)</p></div>
</body>
</html>
<script type="text/javascript">
$(document).ready(function () {
$('#news').news();
});
</script>
Thank you so much all.
Your script needs to be inside the html tags.

Success Header message is showing in browser URL when redirect

I am using spring mvc in my application,when i created user i have to show the success message in a header,
so i used this code
modelAndView.setViewName("redirect:/mainPage");
modelAndView.addObject("successMessage", "user created successfully");
return modelAndView;
But my problem is i am getting this message in browser url. suppose if i use like as below,Success message is showing in a header of mainpage ,but the records in main page disappear.
modelAndView.setViewName("mainPage");
modelAndView.addObject("successMessage", "user created successfully");
return modelAndView;
this is my mainpage.jsp
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%# taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%# taglib prefix="sec" uri="http://www.springframework.org/security/tags" %>
<%# taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<jsp:include page="../templates/header.jsp"></jsp:include>
<script type="text/javascript" src="js/bootstrap-dropdown.js"></script>
<script type="text/javascript">
// Implement checkbox-like buttons
$(".toggle-buttons > .g-button").click(function() {
$(this).siblings(".g-button").removeClass("checked");
$(this).addClass("checked");
});
</script>
<style>
.errorblock {
color: #060505;
background-color: #ffEEEE;
border: 3px solid #ff0000;
padding: 8px;
margin: 16px;
}
.successblock {
color: #060505;
background-color: #9EF2DF;
border: 3px solid #06B98F;
padding: 8px;
margin: 16px;
}
</style>
<c:if test="${not empty errorMessage}">
<div class="errorblock">${errorMessage}</div>
</c:if>
<c:if test="${not empty successMessage}">
<div class="successblock" >${successMessage}</div>
</c:if>
<!-- full width -->
<div class="widget" >
<div class="header"><span><img src="images/icon/color_18/audio_knob.png" alt="dashboard"/>Mobee Robot</span>
</div>
<div class="content" >
<div id="UITab">
<ul class="tabs" >
<li>Mobee User(s)</li>
</ul>
<div class="tab_container" >
<sec:authorize access="hasRole('ROLE_USER')">
<div id="tab1" class="tab_content">
<div class="load_page">
<form>
<div class="tableName inTab">
<h3><img src="images/icon/color_18/user.png" alt="users"/>Mobee Users</h3>
<table id="userData" class="display data_table2">
<thead>
<tr>
<th><div class="th_wrapp">Id</div></th>
<th><div class="th_wrapp">User Name</div></th>
<th><div class="th_wrapp">Email Id</div></th>
<th><div class="th_wrapp">Created By</div></th>
<th><div class="th_wrapp">Created On</div></th>
<th><div class="th_wrapp">Status</div></th>
<th><div class="th_wrapp">Manage</div></th>
</tr>
</thead>
<tbody>
<c:forEach items="${mobeeUsers}" var="mobeeRobotUser">
<tr class="odd gradeX">
<td>${mobeeRobotUser.id}</td>
<td>${mobeeRobotUser.userName} </td>
<td>${mobeeRobotUser.emailId}</td>
<td>${mobeeRobotUser.createdBy}</td>
<td><fmt:formatDate value="${mobeeRobotUser.createdOn}" pattern="dd-MMM-yyyy"/></td>
<td>${mobeeRobotUser.status}</td>
<td>
<span class="tip">
<a id="1" href="<%=request.getContextPath() %>/userdelete?id=${mobeeRobotUser.id}" class="Delete" name="${mobeeRobotUser.userName}" title="Delete">
<img src="images/icon/color_18/close.png"/>
</a>
</span>
</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</form>
</div>
</div><!-- End tab1 -->
</sec:authorize>
</div><!-- End tab Container -->
</div><!-- End UITab -->
<!-- clear fix -->
<div class="clear"></div>
</div><!-- End Content -->
</div><!-- End full width -->
<jsp:include page="../templates/footer.jsp"></jsp:include>
please help me
thanks in advance
Once you do a redirect the value is not preserved. So you are not getting successMessage in the mainPage controller.
See here a similar question.
You can put the value in session as suggested.
Or in the next controller fetch it from the request and then set it to the modelandview.
Best of luck.

Resources