gpt4 book ai didi

spring-mvc - 在DispatcherServlet中找不到HTTP请求的映射

转载 作者:行者123 更新时间:2023-12-03 05:13:11 25 4
gpt4 key购买 nike

我试图访问我的jsp页面,由于某种原因,我收到了错误消息

Hibernate: select person0_.pid as pid1_0_, person0_.age as age2_0_, person0_.city as city3_0_, person0_.gender as gender4_0_, person0_.password as password5_0_, person0_.username as username6_0_ from person person0_ order by person0_.pid
2016-10-04 13:49:53.090 WARN 13276 --- [nio-8080-exec-1] o.s.web.servlet.PageNotFound : No mapping found for HTTP request with URI [/WEB-INF/view/personform.jsp] in DispatcherServlet with name 'dispatcherServlet'
'

enter image description here
PersonController:

@Controller
public class PersonController {
@Autowired
private IPersonService personService;
@Autowired
private MessageSource messageSource;
@Autowired
private LocaleResolver localeResolver;
//@RequestMapping(value="personform")
public ModelAndView user(){
ModelAndView mv = new ModelAndView("personform","person",new Person());
setPageData(mv.getModelMap());
return mv;
}

Appconfig.java:
        package App.config;

import java.util.Locale;
import org.springframework.context.MessageSource;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.i18n.CookieLocaleResolver;
import org.springframework.web.servlet.i18n.LocaleChangeInterceptor;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
@Configuration
@ComponentScan("App")
@Import(DBConfig.class)
@EnableWebMvc
public class AppConfig extends WebMvcConfigurerAdapter {
@Bean
public InternalResourceViewResolver viewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/view/");
resolver.setSuffix(".jsp");
return resolver;
}
@Bean
public MessageSource messageSource() {
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("/WEB-INF/i18/messages");
messageSource.setDefaultEncoding("UTF-8");
return messageSource;
}
@Bean
public LocaleResolver localeResolver(){
CookieLocaleResolver resolver = new CookieLocaleResolver();
resolver.setDefaultLocale(new Locale("en"));
resolver.setCookieName("myLocaleCookie");
resolver.setCookieMaxAge(4800);
return resolver;
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
LocaleChangeInterceptor interceptor = new LocaleChangeInterceptor();
interceptor.setParamName("mylocale");
registry.addInterceptor(interceptor);
}
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/app-resources/**").addResourceLocations("/resources/");
}
}

以防万一,如果需要-build.gradle:
group 'mbti'
version '1.0-SNAPSHOT'

buildscript {
repositories {
maven { url "http://repo.spring.io/libs-snapshot" }
mavenLocal()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.0.1.RELEASE")
}
}

apply plugin: 'java'
apply plugin: 'idea'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8

repositories {
mavenCentral()
maven { url "http://repo.spring.io/libs-snapshot" }
}

dependencies {
compile group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: '1.3.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-data-jpa', version: '1.3.3.RELEASE'
compile group: 'mysql', name: 'mysql-connector-java', version: '5.1.31'
compile group: 'org.apache.commons', name: 'commons-dbcp2', version: '2.1.1'
compile group: 'jstl', name: 'jstl', version: '1.2'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-tomcat', version: '1.3.3.RELEASE'
compile group: 'org.apache.tomcat.embed', name: 'tomcat-embed-el', version: '8.0.32'


testCompile group: 'junit', name: 'junit', version: '4.11'
}

task wrapper(type: Wrapper) {
gradleVersion = '1.11'
}

最佳答案

在您的 Controller 中,取消注释@requestMapping注释,并按如下所示设置值:@RequestMapping(value="/personform")
没有上面的@requestMapping批注,您的 View 解析器将找不到正确的映射。

请注意,无法通过在浏览器中键入uri来直接访问WEB-INF目录下的jsp页面,您必须使用 Controller 或servlet(在您的情况下为 Controller )进行访问。

关于spring-mvc - 在DispatcherServlet中找不到HTTP请求的映射,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39852058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com