为啥突然表单就提交失败了

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为啥突然表单就提交失败了相关的知识,希望对你有一定的参考价值。

有一个小型的新闻发布系统,用ACCESS的,由于其中有一个表里被外来的垃圾信息充斥满了,所以我把这个表删除了,把相应的脚本也删除了。虽然删除表后数据库没有减小(60MB)随后我自己也不能发布消息了(与这个删除的表单没有任何关系)提交后显示超出最长相应时间。。。我随后把其他的表复制到一个新的数据库中瘦身到8M,但是依然无法提交,即使我把删除的表的结构恢复上去,求解!!

参考技术A 引用
2

net_lover
的回复:检查代码执行到哪一步导致,你可以加入调试信息,另外,检查数据库连接是否正确

当我提交 jsf 表单时,应用程序显示 403 错误页面。为啥这个?

【中文标题】当我提交 jsf 表单时,应用程序显示 403 错误页面。为啥这个?【英文标题】:When I submit an jsf form the application show a 403 error page. Why this?当我提交 jsf 表单时,应用程序显示 403 错误页面。为什么这个? 【发布时间】:2020-01-09 23:05:01 【问题描述】:

我使用 Joinfaces 和 primefaces 使用 JSF 编写 Spring Boot 应用程序。 我写了注册表并进行了测试。 当我使用 POST 方法发送表单时,应用程序给我一个 403 错误。 我该如何解决这个问题?

我的注册页面的JSF模板:

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui">
<f:view>


    <h:head>
        <link type="text/css" rel="stylesheet" href="/css/mystyle.css"></link>
    </h:head>

    <h:body>

        <h2>
            <h:outputText value="msg.translate('male')"/>

        </h2>
        <div class="container">
            <div class="card">
                <div class="card-header">
                    <div class="card-header-title">
                        <div><img   src="it-it/assets/images/l1.svg"> </img></div>
                        <p>Crea il tuo account Firenet</p>
                    </div>
                </div>
                <div class="card-content">
                    <h:form >
                        <div class="inputs-row-container">

            <span class="ui-float-label group-first-item">
       <p:inputText id="firstname" value="" style="width: 100%" required="true"/>
                <p:message for="firstname" />
       <p:outputLabel for="@previous" value="msg.translate('signup-form.input.firstname.label')"/>
   </span>
                            <span class="ui-float-label">
       <p:inputText value="" style="width: 100%"/>
       <p:outputLabel for="@previous" value="msg.translate('signup-form.input.lastname.label')"/>
   </span>


                        </div>


                        <span class="ui-float-label group-item">
                            <p:inputText id="emailInput" value="#registrationStepOne.email" style="width: 100%"  ></p:inputText>
       <p:outputLabel for="@previous" value="msg.translate('signup-form.input.email.label')"/>
   </span>
                        <h:message for="emailInput" style="color: red"/>



                        <div class="inputs-row-container">

            <span class="ui-float-label group-first-item">
       <p:inputText value="" style="width: 100%" required="true"/>
       <p:outputLabel for="@previous" value="msg.translate('signup-form.input.password.label')"/>
   </span>
                            <span class="ui-float-label">
       <p:inputText value="" style="width: 100%"/>
       <p:outputLabel for="@previous" value="msg.translate('signup-form.input.repeatpassword.label')"/>
   </span>


                        </div>




                        <p:commandButton action="/registration/secondstep.xhtml" value="Register" />
                    </h:form>


                </div>
            </div>
        </div>
    </h:body>


</f:view>
</html>

我的 JSF 页面的 Java 代码:

import org.apache.commons.validator.routines.EmailValidator;
import org.ocpsoft.rewrite.annotation.Join;
import org.ocpsoft.rewrite.el.ELBeanName;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.validator.ValidatorException;
import java.io.Serializable;


@Scope("session")
@Component(value = "registrationStepOne")
@ELBeanName(value="registrationStepOne")
@Join(path = "/signup/v1/webcreateaccount", to = "/registration/firststep.xhtml")
public class RegistrationStepOne implements Serializable 


    private String email;
    public RegistrationStepOne() 

        //  FacesContext.getCurrentInstance().getViewRoot().setLocale(new Locale("it", "IT"));


    
    public String save() 

        return "/registration/secondstep.xhtml";
    
    // Validate Email
    public void validateEmail(FacesContext context, UIComponent toValidate, Object value) throws ValidatorException 
        String emailStr = (String) value;


        if (!EmailValidator.getInstance(false).isValid(emailStr)) 
            FacesMessage message = new FacesMessage(new ResourceBundleBean().translate("signup-form.input.email.errors.email"));
            throw new ValidatorException(message);
        
    

    public String getEmail() 
        return email;
    

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

Spring Boot 发布请求日志

  : Current WebApplicationContext is not available for processing of AnnotationConfigurationProvider: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.618 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of ClassLoaderConfigurationProvider: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.618 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of ContextSpecifiedConfigurationProvider: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.619 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of DefaultXMLConfigurationProvider: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.622 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of SpringBootBeanNameResolver: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.623 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of DefaultBeanNameResolver: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.624 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of FacesBeanNameResolver: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.624 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of SpringBeanNameResolver: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.635  WARN 20204 --- [0.1-8083-exec-7] unknown.jul.logger                       : Cannot find classes folder: /WEB-INF/classes/
2019-09-07 11:25:40.644 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of WebXmlServletRegistrationProvider: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.644 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of Servlet3ServletRegistrationProvider: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.655 DEBUG 20204 --- [0.1-8083-exec-7] o.s.w.c.s.SpringBeanAutowiringSupport    : Current WebApplicationContext is not available for processing of ContextParamsPostProcessor: Make sure this class gets constructed in a Spring web application. Proceeding without injection.
2019-09-07 11:25:40.658 DEBUG 20204 --- [0.1-8083-exec-7] o.s.web.servlet.DispatcherServlet        : "ERROR" dispatch for POST "/error", parameters=masked

【问题讨论】:

我在这里看不到与 JSF 的任何关系。 403 不是 JSF 通常产生的。所以最好检查你的身份验证框架...... 【参考方案1】:

错误可能是由于Spring CSRF protection。

如果您在 application.properties 中为 Spring 安全性启用调试日志记录 (logging.level.org.springframework.security: debug) 然后你会看到类似的东西

2019-12-24 15:56:33,951   [99] DEBUG         o.s.security.web.csrf.CsrfFilter:doFilterInternal      127 - Invalid CSRF token found for <JSF page>

由于 JSF 已经内置了 CSRF 保护(2,3),您可以通过配置禁用 Spring 自己的 CSRF 保护:

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter 

    @Override
    protected void configure(HttpSecurity http) throws Exception 

        http.csrf().disable();
    
    

另见4。

【讨论】:

这对我有用,谢谢!

以上是关于为啥突然表单就提交失败了的主要内容,如果未能解决你的问题,请参考以下文章

jQuery Validate 提交表单验证失败扩展方法

Layui表单验证失败的提醒方式,怎么改变一下

为啥这个 Vue 3 表单验证脚本会失败?

form表单提交file文件传输失败

验证失败时阻止表单提交(Angular Material)

PHP表单提交失败,如何返回原值?