Extjs和Spring 4

时间:2016-06-24 06:30:26

标签: extjs spring-4

我在集成spring和extjs时遇到错误。它只是登录页面的简单代码。

错误详情如下

  

无法加载资源:服务器响应状态为500   (内部服务器错误)ext-all.js:21未捕获的TypeError:无法读取   属性'isProvider'未定义

带警告

  

找不到带URI的HTTP请求的映射   DispatcherServlet中的[/LoginExt_Spring_20-06/services/api.js]   名称'服务'

//This is my controller code

Ext.define('myapp.controller.LoginController',{
		extend:'Ext.app.Controller',
		stores:['LoginStore'],
		Views:['LoginView','HomeView'],
		refs:[
		      { ref:'loginview'},
		      {ref:'homepage'}
		      ],
		 init:function(){
			 this.control({
				 'loginview button[action=login]':{
					 click:'onLogin'
				 },
				 'loginview button[action=cancel]':{
					 click:'onCancel'
				 }
			 });
		 },
		onLogin:function(button){
			var loginForm=button.up('form[name=loginview]');
			var loginValues=loginForm.getValues();
			var login=loginForm.up('container[name=viewport]');
			var home=login.down('grid[name=homepage]');
			//console.log('loginValues are: '+loginValues.username);
			formController.authenticate(loginValues);
			//if(loginValues.username=='admin'&&loginValues.password=='password'){
				Ext.Msg.alert('status','successfull login');
				loginForm.setVisible(false);
				home.setVisible(true);
			//}else Ext.Msg.alert('status','Invalid credentials...');
		},
		
		onCancel:function(){
			var loginForm=button.up('form[name=loginview]');
			this.loginForm.getForm().reset();
		}
	});


//code in Store

Ext.define('myapp.store.LoginStore',{
		extend:'Ext.data.Store',
		model:'myapp.model.LoginModel',
		autoLoad:true,
		proxy:{
			type:'direct',
			directfn:formController.authenticate,
			reader:{
				type:'json'
			}
		}
		 });

// I included 

Ext.require('Ext.direct.*', function() {
	Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);
});
index.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Jsp page</title>
<script type="text/javascript" src="resources/extjs/ext-all.js"></script> 
  <link rel="stylesheet" href="resources/css/ext-theme-neptune-all.css">
 <script type="text/javascript" src="services/api.js"></script>
 <script type="text/javascript" src="resources/script/app.js"></script>
 <script type="text/javascript">Ext.direct.Manager.addProvider(Ext.app.REMOTING_API);</script>

</head>
<body>
</body>
</html>
  
  
  Application Initializer
  
  import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;

import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;

public class AppInitializer implements WebApplicationInitializer{

	@Override
	public void onStartup(ServletContext container) throws ServletException {
		AnnotationConfigWebApplicationContext context=new AnnotationConfigWebApplicationContext();
		context.register(ApplicationConfig.class);
		context.setServletContext(container);
		
		ServletRegistration.Dynamic servlet=container.addServlet("Dispatcher", new DispatcherServlet(context));
		servlet.setLoadOnStartup(1);
		servlet.addMapping("/services/*");
	}

}
  
  Java Controller
  
  
	@ExtDirectMethod
	public String authenticate(@RequestParam Login cred){
		
		loginDao.userCredentials(cred);
		return "HomeView";
	}

1 个答案:

答案 0 :(得分:1)

您需要在web.xml中提供servlet映射