用request把值回传回来~~~我用了STRUTS框架~所以

解决方案 »

  1.   

    是jsp页面吗?你可以用
    String str =request.getParameter("txtName");
    if(str==null||"".equals(str)){
        str = "";
    }
    <input type="text" name="txtName" value="<%=str%>">
      

  2.   

    我没有把需求说清楚,不是jsp也不是.net,就是一个html页面,用javascript来实现。下面是我写的代码,刷新后页text值没有取回来,大家帮看看。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>SET/GET COOKIE</title>
        <script type="text/javascript">
        function GetCookieVal(offset)
        //获得Cookie解码后的值
        {
            var endstr = document.cookie.indexOf (";", offset);
            if (endstr == -1)
            endstr = document.cookie.length;
            return unescape(document.cookie.substring(offset, endstr));
        }
        function SetCookie(name, value)
        //设定Cookie值
        {
            var expdate = new Date();
            var argv = SetCookie.arguments;
            var argc = SetCookie.arguments.length;
            var expires = (argc > 2) ? argv[2] : null;
            var path = (argc > 3) ? argv[3] : null;
            var domain = (argc > 4) ? argv[4] : null;
            var secure = (argc > 5) ? argv[5] : false;
            if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
            document.cookie = name + "=" + escape (value) +((expires == null) ? "" : ("; expires="+ expdate.toGMTString()))
            +((path == null) ? "" : ("; path=" + path)) +((domain == null) ? "" : ("; domain=" + domain))
            +((secure == true) ? "; secure" : "");
        }
        function DelCookie(name)
        //删除Cookie
        {
            var exp = new Date();
            exp.setTime (exp.getTime() - 1);
            var cval = GetCookie (name);
            document.cookie = name + "=" + cval + "; expires="+ exp.toGMTString();
        }
        function GetCookie(name)
        //获得Cookie的原始值
        {
            var arg = name + "=";
            var alen = arg.length;
            var clen = document.cookie.length;
            var i = 0;
            while (i < clen)
            {
                var j = i + alen;
                if (document.cookie.substring(i, j) == arg)
                return GetCookieVal (j);
                i = document.cookie.indexOf(" ", i) + 1;
                if (i == 0) break;
            }
            return null;
        }    function test(){
        var usrname;
        var txt;
        SetCookie(usrname,document.getElementsByName("Text1")[0].value);    
        document.execCommand('refresh');
        txt = GetCookie(usrname);
        document.getElementsByName("Text1")[0].value = txt;
        }</script>
    </head>
    <body>
        <p>
            <input name="Text1" type="text" onchange='test()'/></p>
    </body>
    </html>
      

  3.   

    没那么复杂吧?你参考一下以下代码。刷新了页面,但text1的值还在。<html> 
    <head> 
    <title>测试</title> 
    <script type="text/javascript">
    function show(){
    var win=location.href;
    if(win.toString().indexOf('?')== -1){
    document.all.text1.value=='';
    }
    else{
    var win1=win.split("=")
    document.all.text1.value=win1[1];
    }
    }
    </script> 
    </head> 
    <body onload="show();">
    <p> 
    <input name="text1" type="text" value="">
    <input name="button" type="button" value="刷新" onclick="javascript:location.reload('?value='+text1.value);">
    </p> 
    </body> 
    </html>
      

  4.   

    var argv = SetCookie.arguments; 
      

  5.   

    xxx.html?name1=value1&name2=value2
    方式传回window.onload=function()
        {
    var url=window.location.href;
    var args = url.split("?");
    if (args[0] != url)
    {
    var str = args[1];
    args = str.split("&");
    for (var i=0; i<args.length; i++)
    {
    var arg = args[i].split("=");
    if (arg.length == 2)
    {
    if (arg[0].toLowerCase() == "name1")
    {
    document.getElementById("name1").value = arg[1];
    }
    else if (arg[0].toLowerCase() == "name2")
    {
    document.getElementById("name2").value = arg[1];
    }
    }
    }
        }
      

  6.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
     <HEAD>
      <TITLE> 使用userData保存文本内容 </TITLE>
      <META NAME="Generator" CONTENT="EditPlus">
      <style>
    .userData {behavior:url(#default#userdata);}
      </style>
      <SCRIPT LANGUAGE="JavaScript">
      <!--
      //保存文本值
    function saveInput(){
    var oInput = form1.otxt;
    oInput.setAttribute("saver",oInput.value);
    oInput.save("XmlData");
    } //读取文本值
    function loadInput(){
    var oInput = form1.otxt;
    oInput.load("XmlData");//载入存储区
    oInput.value = oInput.getAttribute("saver");
    }
      //-->
      </SCRIPT>
     </HEAD> <BODY>
      <form id="form1">
    <INPUT TYPE="text" class="userData" id="otxt">
    <INPUT TYPE="button" value="加载" onclick="loadInput()">
    <INPUT TYPE="button" value="保存" onclick="saveInput()">
      </form>
     </BODY>
    </HTML>