spring mvc を jsf および jquery と統合しようとしています。
3 秒のタイマーが実行され、ページが再レンダリングされますが、ページにはハードコードされたテキストのみが表示されますが、メモリ使用量が急増し、すべてがクラッシュし始めます。これは、乱数が 3 秒ごとに生成されることになっているサンプル ページです。
フォルダ構造
-Web Content
- index.xhtml
- template.xhtml
- rest
- welcome.xhtml
-WEB-INF
- web.xml
- testServlet-servlet.xml
- faces-config.xml
- lib
- *all libraries*
-Java Resources
-src
- com
-controller
-HelloWorld.java
Template.xhtml
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:h="http://java.sun.com/jsf/html" xmlns:ui="http://java.sun.com/jsf/facelets">
<h:head>
<title><ui:insert name="title">Default Title</ui:insert></title>
<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700'
rel='stylesheet' type='text/css' />
</h:head>
<h:body>
<div >
<ui:insert name="content" />
</div>
</h:body>
ようこそ.xhtml
<ui:composition template="../template.xhtml"
xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:a4j="http://richfaces.org/a4j">
<ui:define name="title">
Sample Page
</ui:define>
<ui:define name="content">
<script type="text/javascript"
src="http://code.jquery.com/jquery-1.10.1.min.js" />
<script type="text/javascript">
function ajaxFunction() {
$.ajax({
url : 'welcome.xhtml',
success : function(data) {
$('#result').html(data);
}
});
}
</script>
<script type="text/javascript">
var intervalId = 0;
intervalId = setInterval(ajaxFunction, 3000);
</script>
${message}
SUCCESS:
<p id="result"></p>
</ui:define>
コントローラ
@Controller
@RequestMapping("rest/welcome")
public class HelloWorld
{
@RequestMapping("rest/welcome")
public ModelAndView ajaxTest()
{
return new ModelAndView("rest/welcome", "message",
"This is a test message");
}
@RequestMapping(value = "rest/welcome", method = RequestMethod.GET)
public @ResponseBody
String getTime()
{
Random rand = new Random();
float r = rand.nextFloat() * 100;
String result = "<br>Next Random # is <b>" + r
+ "</b>. Generated on <b>" + new Date().toString() + "</b>";
System.out.println("Debug Message from Controller.."
+ new Date().toString());
return result;
}
}
Web.xml スニペット
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>/faces/*</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>testServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>testServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/testServlet-servlet.xml</param-value>
</context-param>
testSevlet-servlet.xml コンテンツ
<context:component-scan
base-package="com.controller" />
<mvc:annotation-driven />