Ajax Jquery call to java spring controller
Description : The program will helps you to call java spring controller from ajax jquery. To know spring configuration please refer this link. The link shows a Hello world Model View Controller java spring example.
index.jsp
jquery api needed
<script type="text/javascript" src="jquery-1.3.2.js"></script>
<script type="text/javascript" src="jqueryApps.js"></script>
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
These jquery api should be paste in your WEB-INF folder.
jqueryApps.js
function callJavaSpringController(){
var jqueryData = 'java spring mvc';
alert(senderEmail);
$.ajax({
type: "GET",
url: "callcontroller.html",
data: { message : jqueryData }
}).done(function( msg ) {
alert( "Data Saved: " + msg );
});
}
JavaSpringSampleController.java
/**
JavaSpringSampleController class
*/
package net.cfed.oms.controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.cfed.oms.model.SendMailModel;
import net.cfed.oms.service.EmployeeService;
import net.cfed.oms.serviceImpl.EmployeeServiceImpl;
import org.apache.catalina.connector.Request;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
/**
* @author free source codes
*
*/
@Controller
public class JavaSpringSampleController {
@RequestMapping("/callcontroller")
public ModelAndView helloWorld(HttpServletRequest request, HttpServletResponse response) {
String message = "Welcome to";
message = message + request.getParameter("message");
System.out.println(message);
return new ModelAndView("index", "message", message);
}
}
Here is a sample for ajax jquery call to servlet , click on the link
http://javabelazy.blogspot.in/
No comments:
Post a Comment
Your feedback may help others !!!