下面是我的项目结构。
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/*");
}
}
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/");
// }
}
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;
}
}
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;
}
}
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>
问候。
我找到原因了。是关于元标签的。我修改了filmler.jsp,如下所示,它已经起作用了。
<!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>
也许这对某人有帮助。
问候。
问题内容: Optparse,旧版本只是忽略所有无法识别的参数并继续执行。在大多数情况下,这不是理想的,已在argparse中进行了更改。但是在某些情况下,您想忽略任何无法识别的参数并解析您指定的参数。 例如: 反正有覆盖吗? 问题答案: 更换 与 例如,
我有以下序列
我不确定这是否是一个与我没有这台计算机的管理权限有关的问题。任何帮助,以便我可以进一步排除故障,将非常感谢! 谢谢
问题内容: 我使用,当我得到 我删除了构建路径,然后又做了 ,仍然是同样的错误。 问题答案: 该代码不是Java SE的一部分,因此这些类将不在JRE中。您需要找到并下载包含这些类的JAR文件,然后将其添加到Eclipse构建路径中。 (可以在此处下载JAR的一个地方,但是如果此链接中断,可以轻松进行自己的搜索。请转到Maven Central或findjar。)
问题内容: 我有一个jimfs(内存文件系统中的Google)从字节数组中创建的zip文件。当尝试使用打开该文件时,出现错误,提示无法识别该提供程序。我的代码如下: URI类似于:。 堆栈跟踪为: jimfs未与一起列出。它位于分别与 for 相比的单独的类加载器中。 提供者的打印如下: 我尝试基于jimfs ClassLoaderTest示例手动设置类加载器,但没有成功。我在Linux上运行。
问题内容: 有时,我会在页面上寻找可能存在或不存在的元素。我想用/尝试/捕获这种情况,当某些HTML元素不存在时,selenium会抛出该异常。原始例外: 具有讽刺意味的是,它不会让我捕捉到之前抛出的异常吗?代码在这里: 错误在这里: 谷歌搜索/文档整理一无所获…让我感到奇怪的是,selenium可以引发异常但不能捕获它。 问题答案: 您需要先导入异常 然后你可以参考它