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

    1. <tfoot id='Gu5P5'></tfoot>

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

      <legend id='Gu5P5'><style id='Gu5P5'><dir id='Gu5P5'><q id='Gu5P5'></q></dir></style></legend>

        Struts 2 - 意外异常捕获设置'xx'

        Struts 2 - Unexpected Exception caught setting #39;xx#39;(Struts 2 - 意外异常捕获设置xx)
          <tbody id='e6e5V'></tbody>
          <legend id='e6e5V'><style id='e6e5V'><dir id='e6e5V'><q id='e6e5V'></q></dir></style></legend>

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

                  本文介绍了Struts 2 - 意外异常捕获设置'xx'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试将未知数字输入从 HTML Form 提交到 Action 类,并通过 Action 类中的 request Method(Used ServletActionContext) 获取 Input 参数信息.

                  I am trying to submit unknown number input from HTML Form to Action class and fetch the Input parameter information by using request Method(Used ServletActionContext) in the Action class.

                  但它的投掷

                  Unexpected Exception catched setting 'xx' on 'class classname Error setting expression 'xx' with value ['yy', ]

                  由于表单中的输入元素是使用 JS 动态添加的,所以我无法在 Action 类中使用 getter 和 setter.

                  Since input elements in the form are adding dynamically using JS, i am not in the position to have getters and setters in the Action class.

                  如何无异常处理Action类?

                  How to process the Action class without any exceptions?

                  JSP:

                  <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
                  <html>
                  <head>
                  <title>Team Activity Log</title>
                  <SCRIPT language="javascript">
                  function addRow(tableid)
                  {
                   var table = document.getElementById(tableid);
                    var rowCount = table.rows.length;
                     var row = table.insertRow(rowCount);
                  
                      var cell1 = row.insertCell(0);
                      var element1 = document.createElement("select");
                      element1=document.getElementById("sele").cloneNode(true);
                      element1.type="select";
                      cell1.appendChild(element1);
                  
                      var cell2=row.insertCell(1);
                      var element2 = document.createElement("input");
                      element2.type="text";
                      element2.setAttribute("placeholder","E.g:1234");
                      cell2.appendChild(element2);
                  
                      var cell3=row.insertCell(2);
                      var element3 = document.createElement("input");
                      element3.type="text";
                      element3.setAttribute("placeholder","Brief your work");
                      cell3.appendChild(element3);
                  
                      var cell4=row.insertCell(3);
                      var element4 = document.createElement("input");
                      element4.type="text";
                          element4.setAttribute("placeholder","MM min");
                      cell4.appendChild(element4);
                  
                  
                      var cell5=row.insertCell(4);
                      var element5 = document.createElement("img");
                      element5.src="close.png";
                          element5.setAttribute("id","delete");
                          element5.setAttribute("onclick","changeImage(this)");
                      cell5.appendChild(element5);
                  
                  
                  
                      }
                  function changeImage(temp)
                  {
                  (temp.parentElement).parentElement.remove();
                  }
                  function convert(tableid,temp2)
                  {
                  var table=document.getElementById(tableid);
                  console.log(table.rows.length);
                  var hidelement=document.getElementById(temp2);
                  hidelement.setAttribute("value",table.rows.length-1);
                  for(var i=1;i<table.rows.length;i++)
                  {
                  var tt="tt"+i;
                  var rf="rf"+i;
                  var des="des"+i;
                  var eff="eff"+i;
                  console.log("executing function");
                  var elemen=table.rows[i].cells[0].querySelector("*");
                  elemen.setAttribute("name",tt);
                  elemen=table.rows[i].cells[1].querySelector("*");
                  elemen.setAttribute("name",rf);
                  elemen=table.rows[i].cells[2].querySelector("*");
                  elemen.setAttribute("name",des);
                  elemen=table.rows[i].cells[3].querySelector("*");
                  elemen.setAttribute("name",eff);
                  }
                  }
                  </script>
                  </head>
                  <body>
                      <INPUT type="button" value="Add Row" onclick="addRow('matrix')" />
                      <%@ taglib uri="/struts-tags" prefix="s" %>
                      <s:url id="myActionUrl" action="timesheetprocess" />
                      <form action=<s:property value="%{myActionUrl}" />> 
                      <input type="hidden" id="taskcount" value="5">
                  <table id="matrix">
                  <tr>
                      <th>Task Type</th>
                      <th>Reference ID</th>
                      <th>Description</th>
                      <th>Efforts</th>
                      <th></th>
                    </tr>
                    <tr>
                    <td>
                    <select id="sele">
                    <option value="" disabled selected>Select your option</option>
                             <option value="SR">SR</option>
                             <option value="CR">CR</option>
                             <option value="ALM">ALM</option>
                             <option value="INCIDENT">INCIDENT</option> 
                             <option value="OTHER">OTHER</option>
                     </select></TD>
                     <td>
                     <INPUT type="text" placeholder="E.g:1234"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="Brief your work"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="MM min" />
                     </td>
                     <td>
                     <img id="delete" src="close.png" onclick="changeImage(this)">
                     </td>
                     </tr><tr>
                    <td>
                    <select id="sele">
                    <option value="" disabled selected>Select your option</option>
                             <option value="SR">SR</option>
                             <option value="CR">CR</option>
                             <option value="ALM">ALM</option>
                             <option value="INCIDENT">INCIDENT</option> 
                             <option value="OTHER">OTHER</option>
                     </select></TD>
                     <td>
                     <INPUT type="text" placeholder="E.g:1234"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="Brief your work"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="MM min" />
                     </td>
                     <td>
                     <img id="delete" src="close.png" onclick="changeImage(this)">
                     </td>
                     </tr>
                     <tr>
                    <td>
                    <select id="sele">
                    <option value="" disabled selected>Select your option</option>
                             <option value="SR">SR</option>
                             <option value="CR">CR</option>
                             <option value="ALM">ALM</option>
                             <option value="INCIDENT">INCIDENT</option> 
                             <option value="OTHER">OTHER</option>
                     </select></TD>
                     <td>
                     <INPUT type="text" placeholder="E.g:1234"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="Brief your work"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="MM min" />
                     </td>
                     <td>
                     <img id="delete" src="close.png" onclick="changeImage(this)">
                     </td>
                     </tr>
                     <tr>
                    <td>
                    <select id="sele">
                    <option value="" disabled selected>Select your option</option>
                             <option value="SR">SR</option>
                             <option value="CR">CR</option>
                             <option value="ALM">ALM</option>
                             <option value="INCIDENT">INCIDENT</option> 
                             <option value="OTHER">OTHER</option>
                     </select></TD>
                     <td>
                     <INPUT type="text" placeholder="E.g:1234"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="Brief your work"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="MM min" />
                     </td>
                     <td>
                     <img id="delete" src="close.png" onclick="changeImage(this)">
                     </td>
                     </tr>
                     <tr>
                    <td>
                    <select id="sele">
                    <option value="" disabled selected>Select your option</option>
                             <option value="SR">SR</option>
                             <option value="CR">CR</option>
                             <option value="ALM">ALM</option>
                             <option value="INCIDENT">INCIDENT</option> 
                             <option value="OTHER">OTHER</option>
                     </select></TD>
                     <td>
                     <INPUT type="text" placeholder="E.g:1234"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="Brief your work"/>
                     </td>
                     <td>
                     <INPUT type="text" placeholder="MM min" />
                     </td>
                     <td>
                     <img id="delete" src="close.png" onclick="changeImage(this)">
                     </td>
                     </tr>
                     </table>
                      <INPUT type="button" value="Submit" onclick="convert('matrix','taskcount')" />
                   </form> 
                     </body>
                     </html>
                  

                  struts.xml 中的动作标签

                  Action tag in struts.xml

                  <action name="timesheetprocess" class="com.App.Controller.Timesheet.Timeprocess"
                      method="execute">
                      <result name="success">Time.jsp</result>
                  </action>
                  

                  我的动作类:

                  import javax.servlet.http.HttpServletRequest;
                  import org.apache.struts2.ServletActionContext;
                  
                  public class Timeprocess {
                      public String execute() {
                  
                          HttpServletRequest request = ServletActionContext.getRequest();
                          String tt="tt";
                          String rf="rf";
                          String des="des";
                          String eff="eff";
                  
                          for(int i=0;i<Integer.parseInt(request.getParameter("taskcount"));i++)
                          {
                              System.out.println("Task Type :"+ request.getParameter(tt+String.valueOf(i)));
                              System.out.println("Task Type :"+ request.getParameter(rf+String.valueOf(i)));
                              System.out.println("Task Type :"+ request.getParameter(des+String.valueOf(i)));
                              System.out.println("Task Type :"+ request.getParameter(eff+String.valueOf(i)));
                  
                  
                          }
                          return "success";
                  
                  }
                  }
                  

                  推荐答案

                  您可以通过在action config中覆盖拦截器来控制Struts2填充参数的过程.

                  You can control the process of parameters population by Struts2 via overriding interceptors in the action config.

                  <action name="timesheetprocess" class="com.App.Controller.Timesheet.Timeprocess"
                              method="execute">
                     <interceptor-ref name="defaultStack">
                        <param name="params.excludeParams">.*</param>
                     </interceptor-ref>
                     <result name="success">Time.jsp</result>
                  </action>
                  

                  您可以在此处修改 params 拦截器的 excludeParams 属性,以从通过 OGNL 的处理中排除所有参数.

                  There you modify the excludeParams property of the params interceptor to exclude all parameters from processing via OGNL.

                  您应该不会以这种方式得到任何异常,但请确保您已配置 struts.devMode=false

                  You should not get any exception in this way, but make sure you have configured struts.devMode=false

                  <constant name="struts.devMode" value="false" />
                  

                  它应该从输出中删除不必要的警告.如果您仍然在日志中收到任何警告或异常,那么您应该配置您的日志框架以从输出中抑制这些警告或错误.

                  It should remove unnecessary warnings from the output. If you still get any warnings or exceptions in the log, then you should configure your logging framework to suppress those warnings or errors from the output.

                  这篇关于Struts 2 - 意外异常捕获设置'xx'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 的游戏框架.有什么建议吗?)

                  <tfoot id='RgXi2'></tfoot>
                  • <bdo id='RgXi2'></bdo><ul id='RgXi2'></ul>

                          1. <legend id='RgXi2'><style id='RgXi2'><dir id='RgXi2'><q id='RgXi2'></q></dir></style></legend>
                          2. <i id='RgXi2'><tr id='RgXi2'><dt id='RgXi2'><q id='RgXi2'><span id='RgXi2'><b id='RgXi2'><form id='RgXi2'><ins id='RgXi2'></ins><ul id='RgXi2'></ul><sub id='RgXi2'></sub></form><legend id='RgXi2'></legend><bdo id='RgXi2'><pre id='RgXi2'><center id='RgXi2'></center></pre></bdo></b><th id='RgXi2'></th></span></q></dt></tr></i><div id='RgXi2'><tfoot id='RgXi2'></tfoot><dl id='RgXi2'><fieldset id='RgXi2'></fieldset></dl></div>

                              <tbody id='RgXi2'></tbody>

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