简体   繁体   English

如何从注释控制器中的表单获取价值

[英]How to get value from form in an annotation controller

I have some jsp page manage.jsp and form inside it: 我有一些jsp页面manage.jsp和其中的表单:

<form method="POST" action="./manage.form">
    <div style=" float: left;">
        <textarea id="errors" name="errors">${ignoredExceptions}</textarea>
    </div>

    <div id="successOrErrorSave"></div>

    <div style="clear: both;">
        <input type="submit" id="saveIgnoredErrors" style="margin-left: auto; margin-top: 10px;" value="<spring:message code="errorlogging.ignredExceptions.save" />"/>
    </div>
 </form>

And I have some controller ManageController: 我有一些控制器ManageController:

/**
 * The main controller.
 */
@Controller
public class ManageController {

    protected final Log log = LogFactory.getLog(getClass());


    @RequestMapping(value = "/module/manage", method = RequestMethod.GET)
    public void showForm(ModelMap model) {
        GlobalProperty glProp = Context.getAdministrationService().getGlobalPropertyObject(
            Constants.GP_IGNORED_EXCEPTION);
        if (glProp != null) {
            model.addAttribute("ignoredExceptions", glProp.getPropertyValue());
        } else {
            model.addAttribute("ignoredExceptions", "");
        }
    }


    @RequestMapping(value = "module/manage", method = RequestMethod.POST)
    public String processSubmit(@ModelAttribute(value = "ignoredExceptions") String ignoredExceprions, BindingResult result,
                                SessionStatus status) {
        boolean successSave = false;
        GlobalProperty glProp = Context.getAdministrationService().getGlobalPropertyObject(
            ErrorLoggingConstants.ERRROR_LOGGING_GP_IGNORED_EXCEPTION);
        if (glProp != null) {
            glProp.setPropertyValue(ignoredExceprions);
            GlobalProperty saved = Context.getAdministrationService().saveGlobalProperty(glProp);
            System.out.println(saved.getPropertyValue());
                        if (saved != null && saved.getPropertyValue().equals(ignoredExceprions)) {
                successSave = true;
            }
        }
                status.setComplete();
        return "module/manage";
    }
}

When I open manage page in the textarea I'm showing current ignoredExceptions. 当我在文本区域中打开管理页面时,正在显示当前的ignoreExceptions。 I need to save new value of ignoredExceptions, which user entered and after than redirect to the same manage page, which will view new value of ignoredExceptions. 我需要保存某个用户输入的ignoreExceptions的新值,然后再重定向到同一管理页面,该页面将查看ignoreedExceptions的新值。 How can I do this? 我怎样才能做到这一点?

The changed value of ignoredExceptions is tied to the textarea field named errors in the form so you could read the value of errors from the request or as RequestParameter 更改后的ignoreExceptions的值与表单中名为errors的textarea字段相关,因此您可以从请求中或作为RequestParameter读取错误的值

@RequestMapping(value = "module/manage", method = RequestMethod.POST)
public String processSubmit(@RequestParam(value = "errors", required = false) String   ignoredExceprions, BindingResult result,
                            SessionStatus status) {
    boolean successSave = false;
    GlobalProperty glProp = Context.getAdministrationService().getGlobalPropertyObject(
        ErrorLoggingConstants.ERRROR_LOGGING_GP_IGNORED_EXCEPTION);
    if (glProp != null) {
        glProp.setPropertyValue(ignoredExceprions);
        GlobalProperty saved = Context.getAdministrationService().saveGlobalProperty(glProp);
        System.out.println(saved.getPropertyValue());
                    if (saved != null && saved.getPropertyValue().equals(ignoredExceprions)) {
            successSave = true;
        }
    }
            status.setComplete();
    return "module/manage";
}

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM