Не удалось подключить мою страницу jsp к контроллеру Spring - получение ни BindingResult, ни простого целевого объекта для имени компонента - PullRequest
0 голосов
/ 13 июля 2020

Я предоставлю то, что у меня есть. Проблема возникает, когда я пытаюсь открыть страницу учительРегистрация. jsp. Я действительно не знаю, в чем моя проблема, так что не могли бы вы помочь. Кстати, я новичок в Spring.

Это мой логин. jsp страница. Он указан как список приветственных файлов.

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Login</title>
</head>
<body>
    <form action="loginServlet" method="post">  
            Name:<input type="text" name="userName"/><br/>  
            Password:<input type="password" name="userPass"/><br/>  
            <input type="submit" value="login"/>  
        </form>

        <a href="register.jsp" style="text-decoration:none;">You don't have an account? Register now for free!</a>
</body>
</html>

Далее мой регистр. jsp страница. Отсюда я могу go до регистрации учителя. jsp.

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <a href="studentRegistration.jsp" style="text-decoration:none;">Register as a student</a>
    <br>
    <a href="teacherRegistration.jsp" style="text-decoration:none;">Register as a teacher</a>
</body>
</html>

Далее идет регистрация моего учителя. jsp page.

    <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Register teacher</title>
</head>
<body>
    <h3>Welcome, Enter Teacher Details</h3>
        <form:form method="post" action="/register/teacher" modelAttribute="user">
             <table>
                <tr>
                    <td>Username:</td>
                    <td><form:input path="username"/></td>
                </tr>
                <tr>
                    <td>Password:</td>
                    <td><form:input path="password"/></td>
                </tr>
                <tr>
                    <td>Email:</td>
                    <td><form:input path="email"/></td>
                </tr>
                <tr>
                    <td>First name:</td>
                    <td><form:input path="firstName"/></td>
                </tr>
                <tr>
                    <td>Last name:</td>
                    <td><form:input path="lastName"/></td>
                </tr>
                <tr>
                    <td><input type="submit" value="Register"/></td>
                </tr>
            </table>
        </form:form>
</body>
</html>

Это моя конфигурация диспетчера запросов.

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
    xmlns:ctx="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <ctx:annotation-config></ctx:annotation-config>
    <ctx:component-scan base-package="controllers"></ctx:component-scan>

    <bean class = "org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name = "prefix" value = "/webapp/" />
      <property name = "suffix" value = ".jsp" />
   </bean>
</beans>

А это мой класс контроллера.

    @Controller
public class RegistrationController {

    @RequestMapping(value = "/teacherRegistration.jsp", method = RequestMethod.GET)
    public ModelAndView registerGET() {
        return new ModelAndView("teacherRegistration", "user", new User());
    }

    @RequestMapping(value = "/register/teacher", method = RequestMethod.POST)
    public String registerTeacher(@ModelAttribute("user") User user) {
        return null; 
    }
}

У меня также есть объект User, но я не думаю, что мне нужно показывать его здесь - это базовый c объект с геттерами и сеттерами.

Ошибка, которую я я получаю, когда собираюсь регистрироваться. jsp to teacherRegistration. jsp, щелкнув href:

java .lang.IllegalStateException: ни BindingResult, ни простой целевой объект для имени bean-компонента ' user 'доступен как атрибут запроса org.springframework.web.servlet.support.BindStatus. (BindStatus. java: 153)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...