我在編寫web應用程序時遇到了一些問題。 當我使用URL這樣http://localhost:8080/user我有沒有問題,我的應用程序工作正常,但是當我使用的URL,如http://localhost:8080/some-intermediate-node/user我已經沒有任何風格和Java的腳本代碼的網頁。 屬於我展示我的dispatcher servlet配置加載資源的問題Spring mvc
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "com.excbooks.controller")
public class ServletConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/css/**").addResourceLocations("/css");
registry.addResourceHandler("/js/**").addResourceLocations("/js");
}
@Bean
public InternalResourceViewResolver setupViewResolver() {
InternalResourceViewResolver resolver = new InternalResourceViewResolver();
resolver.setPrefix("/WEB-INF/views/");
resolver.setSuffix("");
resolver.setViewClass(JstlView.class);
return resolver;
}
@Override
public void configureDefaultServletHandling(DefaultServletHandlerConfigurer configurer) {
configurer.enable();
}
}
和我的控制器
@Controller
public class MainController {
{
BasicConfigurator.configure();
}
@RequestMapping(value = "/d/login", method = RequestMethod.GET)
public String login(Model model){
return "log-in.html";
}
@RequestMapping(value = "/d/user", method = RequestMethod.GET)
public String userProfile(Model model){
User user = new User();
user.setId(new BigInteger("1"));
user.setUsername("Sashko");
model.addAttribute("user",user);
return "index.jsp";
}
}
鏈接到我的JSP指數https://drive.google.com/file/d/0B42ezhAKqwZlcUEyVkR5amNIaDg/view?usp=sharing
請分享index.jsp的代碼? –
好的。這裏https://drive.google.com/file/d/0B42ezhAKqwZlcUEyVkR5amNIaDg/view?usp=sharing – Jungle
在問題中發佈。 –