2
我在整合spring和extjs時出錯。這只是簡單的登錄頁面代碼。Extjs和Spring 4
錯誤明細如下
Failed to load resource: the server responded with a status of 500 (Internal Server Error) ext-all.js:21 Uncaught TypeError: Cannot read property 'isProvider' of undefined
與警告
No mapping found for HTTP request with URI [/LoginExt_Spring_20-06/services/api.js] in DispatcherServlet with name 'services'
//This is my controller code
Ext.define('myapp.controller.LoginController',{
\t \t extend:'Ext.app.Controller',
\t \t stores:['LoginStore'],
\t \t Views:['LoginView','HomeView'],
\t \t refs:[
\t \t { ref:'loginview'},
\t \t {ref:'homepage'}
\t \t ],
\t \t init:function(){
\t \t \t this.control({
\t \t \t \t 'loginview button[action=login]':{
\t \t \t \t \t click:'onLogin'
\t \t \t \t },
\t \t \t \t 'loginview button[action=cancel]':{
\t \t \t \t \t click:'onCancel'
\t \t \t \t }
\t \t \t });
\t \t },
\t \t onLogin:function(button){
\t \t \t var loginForm=button.up('form[name=loginview]');
\t \t \t var loginValues=loginForm.getValues();
\t \t \t var login=loginForm.up('container[name=viewport]');
\t \t \t var home=login.down('grid[name=homepage]');
\t \t \t //console.log('loginValues are: '+loginValues.username);
\t \t \t formController.authenticate(loginValues);
\t \t \t //if(loginValues.username=='admin'&&loginValues.password=='password'){
\t \t \t \t Ext.Msg.alert('status','successfull login');
\t \t \t \t loginForm.setVisible(false);
\t \t \t \t home.setVisible(true);
\t \t \t //}else Ext.Msg.alert('status','Invalid credentials...');
\t \t },
\t \t
\t \t onCancel:function(){
\t \t \t var loginForm=button.up('form[name=loginview]');
\t \t \t this.loginForm.getForm().reset();
\t \t }
\t });
//code in Store
Ext.define('myapp.store.LoginStore',{
\t \t extend:'Ext.data.Store',
\t \t model:'myapp.model.LoginModel',
\t \t autoLoad:true,
\t \t proxy:{
\t \t \t type:'direct',
\t \t \t directfn:formController.authenticate,
\t \t \t reader:{
\t \t \t \t type:'json'
\t \t \t }
\t \t }
\t \t });
// I included
Ext.require('Ext.direct.*', function() {
\t 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{
\t @Override
\t public void onStartup(ServletContext container) throws ServletException {
\t \t AnnotationConfigWebApplicationContext context=new AnnotationConfigWebApplicationContext();
\t \t context.register(ApplicationConfig.class);
\t \t context.setServletContext(container);
\t \t
\t \t ServletRegistration.Dynamic servlet=container.addServlet("Dispatcher", new DispatcherServlet(context));
\t \t servlet.setLoadOnStartup(1);
\t \t servlet.addMapping("/services/*");
\t }
}
Java Controller
\t @ExtDirectMethod
\t public String authenticate(@RequestParam Login cred){
\t \t
\t \t loginDao.userCredentials(cred);
\t \t return "HomeView";
\t }