Reputation: 101
Below is my jquery code from which i wan't to open editPostion.jsp page in spring mvc.
$('#editRAG').click(function() {
$.ajax({
type : "GET",
cache: false,
//dataType : 'json',
url : "editPosition.jsp",
data: {
posn : $('#RAGVal').val(),
},
success : function(data) {alert('2');
window.location="/editPosition.jsp"
}
});
});
Thanks in advance.
Upvotes: 0
Views: 692
Reputation: 3820
Define a controller with a handler method in it which would return to client the "view" which would render your jsp. There are configurations that you required to do it in your spring mvc.
1.Configure application-context.xml for view resolver, in your case *.jsp
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass"
value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/views/jsp/" />
<property name="suffix" value=".jsp" />
</bean>
Add controller with handler method to return you the required view on GET, i.e. editPosition.jsp
@Controller
public class ViewController{
@RequestMapping(value = "/position", method=RequestMethod.GET)
public ModelAndView getEditPositionView(){
return new ModelAndView("editPosition");
}
}
Your jQuery should look like (partially)
$('#editRAG').click(function() {
$.ajax({
type : "GET",
cache: false,
content-type: application/json
url : "position", //server root + position
data: {
posn : $('#RAGVal').val(),
}
});
});
Upvotes: 0
Reputation: 1098
Don't access JSPs from the client directly. Instead, rely on a controller to serve you the JSP.
For example, you may have a controller mapped to a GET request to /editPosition
that serves you the editPosition.jsp
. In such a case, access the /editPosition
URL in your AJAX call instead.
Upvotes: 1