Before ajax became popular, how did I implement the refreshing of new forms? In fact, this function can be fully implemented with the hidden iframe. Let's look at a small test example.
RyAdd. jsp
<Style type = "javascript/text">
// Global Method
Function reset (){
$ ("TxtID"). val ("");
$ ("TxtName"). val ("");
}
</Script>
<Form action = "xy/ryAdd. action" target = "frame">
<Table>
<Tr>
<Td> NO. </td>
<Td> <input type = "text" name = "txtID" id = "txtID"> </td>
</Tr>
<Tr>
<Td> name </td>
<Td> <input type = "text" name = "txtName" id = "txtName"> </td>
</Tr>
<Tr>
<Td colspan = "2"> <input type = "submit" value = "submit"> </td>
</Tr>
<Tr>
<Td> <span id = "hint"> </span> </td>
</Tr>
</Table>
</Form>
<Iframe name = "frame" style = "display: none"> </iframe>
Action
Public class ryAction
{
Private String msg;
Public String ryAdd ()
{
Try
{
...........
Msg = "added successfully ";
}
Cathc (Exception ex)
{
Msg = ex. getMessage ();
}
Return "result ";
}
......... Omit getter, setter method ..............
}
Strust. xml
<Action name = "ryAdd" class = "cn. xy. ryAction" method = "ryAdd">
<Result name = "result"> result. jsp </result>
</Action>
Result. jsp
<Head>
<Script type = "text/javascript">
Window. onload = function (){
// The prompt information obtained on this page
If (document. getElementById ('subhint '))
{
Var hint = document. getElementById ('subhint'). innerHTML;
// Find the parent page
If (window. parent ){
If (window. parent. reset ){
Window. parent. reset ();
}
If(registry.parent.doc ument. getElementById ('hint ')){
Optional bytes parent.doc ument. getElementById ('hint'). innerHTML = hint;
}
}
}
};
</Script>
</Head>
<Body>
<Span id = "subhint" >$ {requestScope. msg} </span>
</Body>