是什么導(dǎo)致“java.lang.IllegalStateException:BindingResult或bean名稱的普通目標(biāo)對象‘命令’作為請求屬性可用”?這意味著這是一個廣泛的典型的問答文章,為這些類型的問題。我試圖編寫一個SpringMVC Web應(yīng)用程序,用戶可以在這個應(yīng)用程序中將電影名稱添加到內(nèi)存中的集合中。它的配置如下public class Application extends AbstractAnnotationConfigDispatcherServletInitializer {
protected Class<?>[] getRootConfigClasses() {
return new Class<?>[] {};
}
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] { SpringServletConfig.class };
}
protected String[] getServletMappings() {
return new String[] { "/" };
}}和@Configuration@ComponentScan("com.example")public class SpringServletConfig extends WebMvcConfigurationSupport {
@Bean
public InternalResourceViewResolver resolver() {
InternalResourceViewResolver vr = new InternalResourceViewResolver();
vr.setPrefix("WEB-INF/jsps/");
vr.setSuffix(".jsp");
return vr;
}}有一個@Controller類中的com.example包裝@Controllerpublic class MovieController {
private final CopyOnWriteArrayList<Movie> movies = new CopyOnWriteArrayList<>();
@RequestMapping(path = "/movies", method = RequestMethod.GET)
public String homePage(Model model) {
model.addAttribute("movies", movies);
return "index";
}
@RequestMapping(path = "/movies", method = RequestMethod.POST)
public String upload(@ModelAttribute("movie") Movie movie, BindingResult errors) {
if (!errors.hasErrors()) {
movies.add(movie);
}
return "redirect:/movies";
}
public static class Movie {
private String filmName;
public String getFilmName() {
return filmName;
}
public void setFilmName(String filmName) {
this.filmName = filmName;
}
}}應(yīng)用程序配置了上下文路徑。/Example..當(dāng)我發(fā)送GET請求時http://localhost:8080/Example/movies我期望JSP生成一個HTML<form>只有一個文本輸入,用于Movie名稱和提交按鈕,我可以使用它發(fā)送帶有新的POST請求。Movie..為什么JSP servlet不能呈現(xiàn)Spring的<form:form>標(biāo)簽?
3 回答

繁花不似錦
TA貢獻(xiàn)1851條經(jīng)驗 獲得超4個贊

ibeautiful
TA貢獻(xiàn)1993條經(jīng)驗 獲得超6個贊
modelAttribute="movie"
<form:input path="filmName" type="text" id="movie.name" />
- 3 回答
- 0 關(guān)注
- 3751 瀏覽
添加回答
舉報
0/150
提交
取消