当前位置: 首页 > 知识库问答 >
问题:

HTTP状态500-请求处理失败;

姚兴安
2023-03-14

这是我的同意模式

    @Entity
@Table(name = "consents")
public class Consent extends BaseEntity {

    /**

     */
    @OneToOne
    @JoinColumn(name = "provider_id")
    private Provider provider;

    @OneToOne
    @JoinColumn(name = "user_id")
    private User user;

    @OneToOne
    @JoinColumn(name = "friend_id")
    private User friend;


    @OneToOne
    @JoinColumn(name = "document_id")
    private Document document;


    @Column(name = "status")
    private String status;

    /**
     * C
     * @return 
     */
    public void Provider() {
    }

    public Provider getProvider() {
        return this.provider;
    }

    /**
     * 
     * Setter for property pet.
     *
     * @param pet New value of property pet.
     *
     */

    public void setProvider(Provider provider) {
        this.provider = provider;
    }


    public User getUser() {
        return user;
    }


    public void setUser(User user) {
        this.user = user;
    }


    public User getFriend() {
        return friend;
    }


    public void setFriend(User friend) {
        this.friend = friend;
    }


    public Document getDocument() {
        return document;
    }


    public void setDocument(Document document) {
        this.document = document;
    }


    public String getStatus() {
        return status;
    }


    public void setStatus(String status) {
        this.status = status;
    }



}

这是同意控制器获取声明

@RequestMapping(value = "/users/{userId}/providers/{providerId}/documents/{documentId}/consents/new", method = RequestMethod.GET)
public String initNewConsentForm(@PathVariable("userId") int userId,@PathVariable("providerId") int providerId,@PathVariable("documentId") int documentId, Model model) {
    User user = this.clinicService.findUserById(userId);
    Provider provider = this.clinicService.findProviderById(providerId);
    Document document = this.clinicService.findDocumentById(documentId);
    Collection<User> users = this.clinicService.AllUsers();



    Consent consent = new Consent();
        //document.addConsent(consent);
        //provider.addDocument(document);
        //user.addProvider(provider);
        model.addAttribute("provider",provider);
        model.addAttribute("document", document);
        model.addAttribute("user", user);
        model.addAttribute("users", users);
        model.addAttribute("consent", consent);
        return "providers/createOrUpdateConsentForm";

}

这是声明后的同意

 @RequestMapping(value = "/users/{userId}/providers/{providerId}/documents/{documentId}/consents/new", method = RequestMethod.POST)
public String processNewConsentForm(@PathVariable("userId") int userId, @PathVariable("providerId") int providerId, 
        @PathVariable("documentId") int documentId, @ModelAttribute("consent") Consent consent, BindingResult result, SessionStatus status) {


    User user = this.clinicService.findUserById(userId);
    Provider provider = this.clinicService.findProviderById(providerId);
    //System.out.println("daghade");
    //System.out.println(provider);
    //Document doc = this.clinicService.findDocumentById(userId);

     Consent c =new Consent();

        c.setProvider(consent.getProvider());
        c.setDocument(consent.getDocument());
        c.setUser(user);
        c.setStatus(consent.getStatus());
        c.setFriend(consent.getFriend());
        System.out.print("consentcontroller11");
        System.out.println(consent.getProvider());
        System.out.print("consentcontroller11");
    if (result.hasErrors()) {
        return "providers/createOrUpdateConsentForm";
    } else {
        this.clinicService.saveConsent(c);
        status.setComplete();
    return "redirect:/users/{userId}";
}

}

同意html thymeleaf表单是

                          <form th:object="${consent}" action="../users/userDetails.html" th:action="@{${#httpServletRequest.servletPath}}" method="post">
                             <fieldset>
                                        <div class="col-sm-7 col-md-6 col-lg-5">
                                        <label for="last_name">Service  Provider</label>
                                        <select th:field="*{document.provider.id}" name="provider" id="provider" class="form-control" th:onchange="'javascript:showPIIDoc(this.value);'">
                                                <option th:value="0" >Select a Service Provider</option>
                                                <option th:each="provider : ${user.providers}"  th:value="${user.id} +','+ ${provider.id}" th:text="${provider.name}" >[name]</option>
                                            </select>

                                        </div>  
                                        <div style="clear:both"></div>
                                        <div class="col-sm-7 col-md-6 col-lg-5">
                                        <label for="last_name">PII Document</label>
                                            <select th:field="*{document.id}"  id ="document_id"  class="form-control">

                                            </select>
                                        </div>  
                                        <div style="clear:both"></div>

                                            <div class="col-sm-7 col-md-6 col-lg-5">
                                        <label for="last_name">Share with</label>
                                            <select th:field="*{user.id}" id="friend_id"  class="form-control">
                                                <option th:value="0" >Select a user you want share the document to</option>
                                                <option name="name" th:each="user : ${users}" th:value="${user.id}" th:text="${user.firstName} + ' ' + ${user.lastName}">[name]</option>
                                            </select>
                                        </div>
                                        <div style="clear:both"></div>
                                        <div class="col-sm-7 col-md-6 col-lg-5">
                                            <label for="last_name">Consent</label>
                                            <div style="clear:both"></div>
                                            <input type="checkbox" id="status" th:field="*{status}" name="share" th:value="1" th:text="Share" />
                                         </div> 

                                         <div style="clear:both"></div>

                            <div style="margin-top:10px;margin-left:10px" class="form-actions">
                                <button class="btn btn-primary" type="submit">Add Consent</button>

                            </div>
                          </fieldset>
                        </form>

提交表格后。我得到这个错误

HTTP状态500-请求处理失败;嵌套异常是org.thymeleaf.exceptions.TemplateProcessing异常:异常评估SpringEL表达式:"user.providers"(提供者/createOrUpdateConentForm

组织。springframework。表示斯佩尔。SpelEvaluationException:EL1007E:(位置0):在null上找不到字段或属性“providers”

我的用户类:

    @Entity
@Table(name = "users")
public class User extends Person {
    @Column(name = "gender")
    @NotEmpty
    private String gender;


    @Column(name = "birth_date")
    private String birthDate;

    @Column(name = "email")
    @NotEmpty
    private String email;

    @Column(name = "username")
    @NotEmpty
/*    @Digits(fraction = 0, integer = 10)*/
    private String username;

    @Column(name = "password")
    @NotEmpty
/*    @Digits(fraction = 0, integer = 10)*/
    private String password;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Provider> providers;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "user")
    private Set<Document> documents;

    @JsonManagedReference
    @OneToOne(cascade = CascadeType.ALL, mappedBy = "user")
    private Role role;

    public void setProviders(Set<Provider> providers) {
        this.providers = providers;
    }
    public void setDocuments(Set<Document> documents) {
        this.documents = documents;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getBirthDate() {
        return birthDate;
    }

    public void setBirthDate(String birthDate) {
        this.birthDate = birthDate;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    protected void setProvidersInternal(Set<Provider> providers) {
        this.providers = providers;
    }

    protected void setDocumentsInternal(Set<Document> documents) {
        this.documents = documents;
    }


    protected Set<Provider> getProvidersInternal() {
        if (this.providers == null) {
            this.providers = new HashSet<Provider>();
        }
        return this.providers;
    }


    protected Set<Document> getDocumentsInternal() {

        if (this.documents == null) {
            this.documents = new HashSet<Document>();
        }
        return this.documents;
    }

    public List<Provider> getProviders() {
        List<Provider> sortedProviders = new ArrayList<Provider>(getProvidersInternal());
        PropertyComparator.sort(sortedProviders, new MutableSortDefinition("name", true, true));
        System.out.print("sortedProvider");
        System.out.print(sortedProviders);

        return Collections.unmodifiableList(sortedProviders);
    }

    public List<Document> getDocuments() {
        List<Document> sortedDocuments = new ArrayList<Document>(getDocumentsInternal());
        PropertyComparator.sort(sortedDocuments, new MutableSortDefinition("name", true, true));
        System.out.print("sortedDocuments");
        System.out.print(sortedDocuments);
        return Collections.unmodifiableList(sortedDocuments);
    }


    public void addProvider(Provider provider) {
        getProvidersInternal().add(provider);
        provider.setUser(this);
    }

    public void addDocument(Document document, Provider provider) {
        getDocumentsInternal().add(document);
        System.out.print("addDocument");
        System.out.print(document);
        document.setUser(this);
        document.setProvider(provider);
        System.out.print("addDocument");
        System.out.print(document);

    }
    /**
     * Return the Pet with the given name, or null if none found for this Owner.
     *
     * @param name to test
     * @return true if pet name is already in use
     */
    public Provider getProvider(String name) {
        return getProvider(name, false);
    }

    public Document getDocument(String name) {
        return getDocument(name, false);
    }

    /**
     * Return the Pet with the given name, or null if none found for this Owner.
     *
     * @param name to test
     * @return true if pet name is already in use
     */
    public Provider getProvider(String name, boolean ignoreNew) {
        name = name.toLowerCase();
        for (Provider provider : getProvidersInternal()) {
            if (!ignoreNew || !provider.isNew()) {
                String compName = provider.getName();
                compName = compName.toLowerCase();
                if (compName.equals(name)) {
                    return provider;
                }
            }
        }
        return null;
    }

    public Document getDocument(String name, boolean ignoreNew) {
        name = name.toLowerCase();
        for (Document document : getDocumentsInternal()) {
            if (!ignoreNew || !document.isNew()) {
                String compName = document.getName();
                compName = compName.toLowerCase();
                if (compName.equals(name)) {
                    return document;
                }
            }
        }
        return null;
    }



    public Role getRole() {
        return role;
    }

    public void setRole(Role role) {
        this.role = role;
    }

    @Override
    public String toString() {
        return new ToStringCreator(this)

                .append("id", this.getId())
                .append("new", this.isNew())
                .append("lastName", this.getLastName())
                .append("firstName", this.getFirstName())
                .append("gender", this.gender)
                .append("bithDate", this.birthDate)
                .append("email", this.email)
                .append("username", this.username)
                .append("password", this.password)
                .toString();
    }
}

共有1个答案

梁承恩
2023-03-14

错误消息告诉user模型属性为null

在post请求映射中添加模型属性,如下所示

@RequestMapping(value = "/users/{userId}/providers/{providerId}/documents/{documentId}/consents/new", method = RequestMethod.POST)
public String processNewConsentForm(Model model, @PathVariable("userId") int userId, @PathVariable("providerId") int providerId, 
        @PathVariable("documentId") int documentId, @ModelAttribute("consent") Consent consent, BindingResult result, SessionStatus status) {

    ...
    if (result.hasErrors()) {

        User user = this.clinicService.findUserById(userId);
        Provider provider = this.clinicService.findProviderById(providerId);
        Document document = this.clinicService.findDocumentById(documentId);
        Collection<User> users = this.clinicService.AllUsers();

        model.addAttribute("provider",provider);
        model.addAttribute("document", document);
        model.addAttribute("user", user);
        model.addAttribute("users", users);
        model.addAttribute("consent", consent);

        return "providers/createOrUpdateConsentForm";
    } 
    ...
}
 类似资料:
  • 我现在正在使用JPA eclipselink,我想用Eclipselink连接到我的数据库 我有一些类de表在我的数据库和查询来获取我的条目: 我为我的桌子做了一些课程: FDC_DBCHANGE 已执行FDC_ 和FDC_系统 当我在Tomcat上运行它时,有一个例外: 组织。springframework。网状物util。NestedServletException:请求处理失败;嵌套异常是异

  • 我有jsp和html页面的应用程序 说明服务器遇到一个内部错误,使其无法满足此请求。 例外 NestedServletException:处理程序处理失败;嵌套异常是java.lang.NosuchMethoderror:javax.servlet.http.HttpServletResponse.getHeader(ljava/lang/string;)ljava/lang/string;rig

  • 请帮助我更好地学习Spring 3 MVC的基础知识,我试图学习Spring JSR303:Bean验证,但根本无法解决以下问题,我已经花了一天多的时间来解决这个问题:( 我想要一个简单的验证在这里工作。jsp中的name、password和email字段不能留空,这是我们的目标。到目前为止,每次尝试将所有字段都为空提交hello.jsp时,都会遇到以下错误 HTTP状态500-处理程序处理失败;

  • 我的资源 index.jsp HTTP状态500-servlet Jersey Web应用程序的servlet.init()引发异常 类型异常报告 servlet Jersey Web应用程序的消息servlet.init()引发异常 Apache Tomcat/8.0.43

  • 好的,我在运行我的应用程序时遇到了这个问题,我相信这是因为版本控制。 秋季开始,我使用Tomcat 9.0.4。我使用最新的JavaSDK。 现在,我使用的是Spring版本5.0.2。 这是我的pom。xml: 这是我的web.xml: 这是我的调度器servlet。xml: 现在,我想提一件事:看看那些?我不确定这是否正确。为什么?这就是我在输出中得到的错误: 现在,我知道这是一大段文字,你可

  • 我正在使用Eclipse和Tomcat Server 7开发一个带有String框架的web应用程序。当我运行它时,我总是得到同样的错误: HTTP状态500-处理JSP页面/views/misc/index时发生异常。jsp第19行 第19行是:<代码> 有时候在我不停刷新页面的时候是可以的,但是不知道为什么。 misc/index.jsp 这是欢迎视图的index.jsp页面 堆栈跟踪: 根本