I am new to spring MVC framework. I got stuck at one point. i want to display another jsp page from my current jsp page.for that i use ajax on client side. I am sharing my code in below. Please help me out to solve this. Thanks,
<li>
<a href="" onclick="displayEditProfile();" target="_blank">
<i class="glyphicon glyphicon-edit"></i>
Edit My Profile </a>
</li>
my Javascript Function is :
function displayEditProfile(){
$.ajax({
url: '/HappyWorld/displayEditProfile.do',
data:{
//sharePost : $('#userPost').val(),
//"password":$('#passwordId').val(),
time : new Date(),
},
type: 'GET',
dataType: 'text',
success: function(data) {
},
error: function(xhr, textStatus, errorThrown) {
alert(xhr+" "+textStatus+" "+errorThrown);
}
});
}
My controller is :
@RequestMapping(value="/displayEditProfile", method = RequestMethod.GET)
@ResponseBody
public ModelAndView displayEditProfile(HttpServletRequest request,HttpServletResponse response) {
System.out.println(" in call.");
return new ModelAndView("edit_user_profile");
}
and my xml configuration for view is:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:prefix="/jsp/" p:suffix=".jsp" />
You don't need ajax to redirect.You can directly use
<a href="displayEditProfile" target="_blank">
<i class="glyphicon glyphicon-edit"></i>
Edit My Profile </a>
if you want to pass some parameters you can submit the form with action=displayEditProfile and have the form fields.
<form action="displayEditProfile" >
您必须删除@ResponseBody。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.