如何通过JSP代码将隐藏字段(Javascript)插入XML?

时间:2012-08-14 03:24:04

标签: javascript xml jsp hidden

我正在尝试将来自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中。我试过,但它出来的'null'。有没有人可以帮我解决这个问题?非常感谢!

1 个答案:

答案 0 :(得分: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);
%>