问题
my Project structure is below.
ControllerConfiguration.java
package org.java.springmvc.bootstrap;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "org.java.springmvc.controller")
public class ControllerConfiguration {
@Bean
public InternalResourceViewResolver configureInternalResourceViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix(".jsp");
return resolver;
}
}
WebAppInitializer.java
package org.java.springmvc.bootstrap;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration.Dynamic;
import org.springframework.web.WebApplicationInitializer;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
import org.springframework.web.servlet.DispatcherServlet;
public class WebAppInitializer implements WebApplicationInitializer {
@Override
public void onStartup(final ServletContext servletContext) throws ServletException {
final AnnotationConfigWebApplicationContext root = new AnnotationConfigWebApplicationContext();
root.setServletContext(servletContext);
root.scan("org.java.springmvc.bootstrap");
root.refresh();
final Dynamic servlet = servletContext.addServlet("spring", new DispatcherServlet(root));
servlet.setLoadOnStartup(1);
servlet.addMapping("/views/*");
}
}
WebMvcConfigAdapter.java
package org.java.springmvc.bootstrap;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
@EnableWebMvc
public class WebMvcConfigAdapter extends WebMvcConfigurerAdapter {
// @Override
// public void addResourceHandlers(ResourceHandlerRegistry registry) {
// registry.addResourceHandler("/js/**").addResourceLocations("/js/");
// }
}
WebMvcConfigSupport.java
package org.java.springmvc.bootstrap;
import java.util.List;
import org.springframework.context.annotation.Bean;
import org.springframework.http.converter.HttpMessageConverter;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;
public class WebMvcConfigSupport extends WebMvcConfigurationSupport {
protected void configureMessageConverters(List<HttpMessageConverter<?>> converters) {
converters.add(converter());
addDefaultHttpMessageConverters(converters);
}
@Bean
MappingJackson2HttpMessageConverter converter() {
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
//do your customizations here...
return converter;
}
}
FilmController.java
package org.java.springmvc.controller;
//import java.io.IOException;
//import java.io.Writer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.java.springmvc.model.Film;
import org.java.springmvc.model.Film.FilmTurleri;
import org.springframework.stereotype.Controller;
//import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
@RequestMapping("/film")
public class FilmController {
//
// @RequestMapping(value = "filmler")
// public void filmler(final Writer writer)
// throws IOException {
// writer.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-9\"><title>...Filmler...</title>");
// writer.append("<script type=\"text/javascript\" src=\"/js/touch/sencha-touch-all.js\"></script>");
// writer.append("<script type=\"text/javascript\" src=\"/js/film/filmler.js\"></script>");
// writer.append("</head><body></body></html>");
//
// }
@RequestMapping (value = "filmleriGetir", method = RequestMethod.GET)
public @ResponseBody Map<String, List<Film>> FilmleriGetir() {
List<Film> movies = new ArrayList<Film>();
// For testing...
movies.add(new Film(0, "Birinci Film", "Birinci Yönetmen", 2015, FilmTurleri.Aksiyon));
movies.add(new Film(0, "İkinci Film", "İkinci Yönetmen", 2015, FilmTurleri.Komedi));
movies.add(new Film(0, "Üçüncü Film", "Üçüncü Yönetmen", 2015, FilmTurleri.Aile));
Map<String, List<Film>> resp = new HashMap<String, List<Film>>();
resp.put("filmListesi", movies);
return resp;
}
@RequestMapping("ttt")
public @ResponseBody Film getPerson(){
Film film = new Film(0, "Birinci Film", "Birinci Yönetmen", 2015, FilmTurleri.Aksiyon);
return film;
}
}
HomeController.java
package org.java.springmvc.controller;
import java.io.IOException;
import java.io.Writer;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class HomeController {
@RequestMapping(value = "/")
public void home(final Writer writer)
throws IOException {
writer.append("<h2>Welcome, XML Free Spring MVC!</h2>");
}
@RequestMapping(value = "/giris")
public void giris(final Writer writer)
throws IOException {
writer.append("Giris");
}
}
Film.java
package org.java.springmvc.model;
public class Film {
public int Id;
public String FilmAdi, Yonetmen;
public int CikisTarihi;
public FilmTurleri Turu;
public enum FilmTurleri {
Aksiyon, Komedi, Aile, Korku, Savas;
}
public Film(){
}
public Film(int id, String title, String director, int yearOfRelease, FilmTurleri tur)
{
super();
this.Id = id;
this.FilmAdi = title;
this.Yonetmen = director;
this.CikisTarihi = yearOfRelease;
this.Turu = tur;
}
//getter, settings method
}
filmler.js
Ext.application({
name: 'Sencha',
launch: function() {
var touchTeam = Ext.create('Ext.DataView', {
fullscreen: true,
store: {
fields: ['name', 'age'],
data: [
{name: 'Greg', age: 100},
{name: 'Brandon', age: 21},
{name: 'Scott', age: 21},
{name: 'Gary', age: 24},
{name: 'Fred', age: 24},
{name: 'Seth', age: 26},
{name: 'Kevin', age: 26},
{name: 'Israel', age: 26},
{name: 'Mitch', age: 26}
]
},
itemTpl: '{name} is {age} years old'
});
}
});
// if i achieve to run the code above, i'll try to get the data from server side like below.
//Ext.application({
// name : 'Fiddle',
//
// launch : function() {
//
// var store = Ext.create('Ext.data.Store', {
// autoLoad: true,
// fields: ['title'],
// proxy: {
// type: 'jsonp',
// url: uygulamaAdi + '/filmleriGetir',
// reader: {
// rootProperty: 'topics',
// totalProperty: 'totalCount'
// }
// }
// });
//
// Ext.create('Ext.DataView', {
// fullscreen: true,
// store: store,
// itemTpl: '{title}'
// });
// }
//});
filmler.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-9"
pageEncoding="ISO-8859-9"%>
<!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-9">
<title>Filmler</title>
<script type="text/javascript" src="../../js/touch/ayarlar.js"></script>
<script type="text/javascript" src="../../js/film/filmler.js"></script>
</head>
<body>
</body>
</html>
My logic is calling classic jsp file from under WebContent/jsp. there is main js file in jsp. it will get the data from server side with MVC. but in first test example, basic dataview does not appear. Chrome console screen is below.
i understood nothing from these warning and errors? any help?
regards.
回答1:
i've found the reason. it's about meta tags. i've changed filmler.jsp like below and it has worked.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<meta name="msapplication-tap-highlight" content="no"/>
<title>Filmler</title>
<link rel="stylesheet" href="../../js/touch/resources/css/sencha-touch.css" type="text/css">
<script type="text/javascript" src="../../js/touch/ayarlar.js"></script>
<script type="text/javascript" src="../../js/film/filmler.js"></script>
</head>
<body>
</body>
</html>
maybe it helps someone.
regards.
来源:https://stackoverflow.com/questions/34986950/sencha-touch-2-the-key-minimum-ui-is-not-recognized-and-ignored