1. <legend id='P4bZS'><style id='P4bZS'><dir id='P4bZS'><q id='P4bZS'></q></dir></style></legend>

    <i id='P4bZS'><tr id='P4bZS'><dt id='P4bZS'><q id='P4bZS'><span id='P4bZS'><b id='P4bZS'><form id='P4bZS'><ins id='P4bZS'></ins><ul id='P4bZS'></ul><sub id='P4bZS'></sub></form><legend id='P4bZS'></legend><bdo id='P4bZS'><pre id='P4bZS'><center id='P4bZS'></center></pre></bdo></b><th id='P4bZS'></th></span></q></dt></tr></i><div id='P4bZS'><tfoot id='P4bZS'></tfoot><dl id='P4bZS'><fieldset id='P4bZS'></fieldset></dl></div>
    <tfoot id='P4bZS'></tfoot>
      <bdo id='P4bZS'></bdo><ul id='P4bZS'></ul>

    1. <small id='P4bZS'></small><noframes id='P4bZS'>

      用保存的 cookie 填写表格

      Fill a form with saved cookies(用保存的 cookie 填写表格)
      • <tfoot id='Reaxt'></tfoot>
        1. <i id='Reaxt'><tr id='Reaxt'><dt id='Reaxt'><q id='Reaxt'><span id='Reaxt'><b id='Reaxt'><form id='Reaxt'><ins id='Reaxt'></ins><ul id='Reaxt'></ul><sub id='Reaxt'></sub></form><legend id='Reaxt'></legend><bdo id='Reaxt'><pre id='Reaxt'><center id='Reaxt'></center></pre></bdo></b><th id='Reaxt'></th></span></q></dt></tr></i><div id='Reaxt'><tfoot id='Reaxt'></tfoot><dl id='Reaxt'><fieldset id='Reaxt'></fieldset></dl></div>
            • <bdo id='Reaxt'></bdo><ul id='Reaxt'></ul>
                <tbody id='Reaxt'></tbody>
              <legend id='Reaxt'><style id='Reaxt'><dir id='Reaxt'><q id='Reaxt'></q></dir></style></legend>

              <small id='Reaxt'></small><noframes id='Reaxt'>

                本文介绍了用保存的 cookie 填写表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有一个像这样保存我的 cookie 的操作类:

                I have an action class that saves my cookies like this:

                public String execute() {
                
                    // Save to cookie
                      Cookie name = new Cookie("name", userInfo.getName() );
                      name.setMaxAge(60*60*24*365); // Make the cookie last a year!
                      servletResponse.addCookie(name);
                }
                

                如果我提交表单,我可以在浏览器上看到已创建并保存的 cookie.当用户提交时,他们会被重定向到一个新页面,该页面包含他们刚刚创建的所有存储信息.

                If I submit my form, I can see the cookies on the browser that has been created and saved. When the user submits, they get redirected to a new page, a page with all the stored information that they just created.

                我希望用户能够返回提交页面并查看他们刚刚提交的表单中的所有信息.是否可以使用 Struts2 执行此操作,使用保存的 Cookie 并获取表单以填写旧数据?

                I want the user to be able to go back to the submit page and see all the information in the forms that they just submitted. Is it possible to do this with Struts2, by using the saved Cookies and get the form to fill in with the old data?

                这是我的表格:

                <s:textfield
                        label="Name"
                        name="name"
                        key="name" 
                        tooltip="Enter your Name here"/>
                

                推荐答案

                要发送 cookie,您可以使用 cookie-provider 拦截器.它允许您通过实现 CookieProvider 在操作中填充 cookie.要将此拦截器应用于操作配置,您可以覆盖拦截器配置

                To send cookie you can use a cookie-provider interceptor. It allows you to populate cookies in the action via implementing CookieProvider. To apply this interceptor to the action configuration you can override the interceptors config

                <action ... >
                  <interceptor-ref name="defaultStack"/>
                  <interceptor-ref name="cookieProvider"/>
                  ...
                </action> 
                

                CookieProvider有方法实现,

                public class MyAction extends ActionSupport implements CookieProvider {
                
                    @Override
                    public Set<Cookie> getCookies(){
                      Set<Cookie> cookies = new HashSet<>();
                      Cookie name = new Cookie("name", userInfo.getName() );
                      name.setMaxAge(60*60*24*365); // Make the cookie last a year!
                      name.setPath("/"); //Make it at root.
                      cookies.add(name);
                      return cookies;
                    }
                
                }
                

                在表格中

                <s:set var="name">${cookie["name"].value}</s:set>
                <s:textfield
                        label="Name"
                        name="name"
                        value="%{#name}"
                        tooltip="Enter your Name here"/>
                

                这篇关于用保存的 cookie 填写表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                相关文档推荐

                Java Bytecode Manipulation Library Suggestions(Java 字节码操作库建议)
                Java CLI UI-design: frameworks or libraries?(Java CLI UI 设计:框架还是库?)
                About the use of Beans.xml configuration file in Spring Framework application(关于Spring Framework应用中Beans.xml配置文件的使用)
                What is the difference between Spring, Struts, Hibernate, JavaServer Faces, Tapestry?(Spring、Struts、Hibernate、JavaServer Faces、Tapestry 有什么区别?)
                Are there any android application framework like spring?(有没有像spring这样的android应用程序框架?)
                Java Swing based game framework. Any advice?(基于 Java Swing 的游戏框架.有什么建议吗?)

                    <tbody id='21qPX'></tbody>
                    <bdo id='21qPX'></bdo><ul id='21qPX'></ul>
                    <tfoot id='21qPX'></tfoot>
                        • <small id='21qPX'></small><noframes id='21qPX'>

                        • <legend id='21qPX'><style id='21qPX'><dir id='21qPX'><q id='21qPX'></q></dir></style></legend>

                          <i id='21qPX'><tr id='21qPX'><dt id='21qPX'><q id='21qPX'><span id='21qPX'><b id='21qPX'><form id='21qPX'><ins id='21qPX'></ins><ul id='21qPX'></ul><sub id='21qPX'></sub></form><legend id='21qPX'></legend><bdo id='21qPX'><pre id='21qPX'><center id='21qPX'></center></pre></bdo></b><th id='21qPX'></th></span></q></dt></tr></i><div id='21qPX'><tfoot id='21qPX'></tfoot><dl id='21qPX'><fieldset id='21qPX'></fieldset></dl></div>