0

我正在尝试将 Javascript 隐藏字段中的数据插入 XML,但是只有“null”出现。我已经声明了变量,但它似乎无法捕获隐藏字段。我束手无策,希望我的问题能得到解决。

**<<-----I use session to pass the value to the XML page----->>**


<%
String X = (String)session.getAttribute("X");
    String Y = (String)session.getAttribute("Y");
    String W = (String)session.getAttribute("W");
    String H = (String)session.getAttribute("H");       
session.setAttribute("X",X);
session.setAttribute("Y",Y);
session.setAttribute("W",W);
session.setAttribute("H",H);
%>



**<<------Snippet of Javascript codes------->>**

function moveIt(){ 

if (!moveEnabled||!MovableItem) return;

// display info during testing

X = MovableItem.offsetLeft;

Y = MovableItem.offsetTop;

W = MovableItem.offsetWidth;

H = MovableItem.offsetHeight;

 ==Some codes here==

  document.getElementById('X').value = X;     
  document.getElementById('Y').value = Y;
  document.getElementById('W').value = W;
  document.getElementById('H').value = H;  

}

**<<-----JSP codes that I need to pass the values onto an XML----->>**

 <form name='form1' action='UpdateXML.jsp' method='post'>

<input type='hidden' name=source value="<%=src%>" />
<input type='hidden' id="X" name="X" value="<%=X%>"/>
<input type='hidden' id="Y" name="Y" value="<%=Y%>"/>
<input type='hidden' id="W" name="W" value="<%=W%>"/>
<input type='hidden' id="H" name="H" value="<%=H%>"/> 

<button type="button" onclick="window.location.href='editcompany.jsp'">Back!</button>
<button type="submit">Insert Into XML!</button>
</form>

我需要将隐藏字段(数据)插入 XML。我试过了,但它显示为“空”。有没有人可以帮我解决这个问题?非常感谢!

4

1 回答 1

0

第一个文件是UpdateXML.jsp 吗?如果是这样,不应该有request.getParameter()吗?

似乎下面的 4 行 session.setAttribute() 没有任何用处:

<%
String X = (String)session.getAttribute("X");
String Y = (String)session.getAttribute("Y");
String W = (String)session.getAttribute("W");
String H = (String)session.getAttribute("H");       
session.setAttribute("X",X);
session.setAttribute("Y",Y);
session.setAttribute("W",W);
session.setAttribute("H",H);
%>
于 2012-08-14T03:34:01.507 回答