html源代码
<title></title>
<style>
body {
    MARGIN: 0 0 0 0;
    background-color: #e1e9f4;
}
</style>
<META content="MSHTML 6.00.2800.1625" name=GENERATOR>
</head><body onload="init()" topmargin="0" leftmargin="0" bgcolor="#e1e9f4"> 
<form name="login" action="redirct_index.htm" method="post" onsubmit="return formSubmit2(this);">
<input type=hidden name=rtime>
<SCRIPT language=javascript> 
dis_login(); 
</SCRIPT> 
</form>
</body>
<SCRIPT language=JavaScript></SCRIPT></html>HTML中就一个JS,JS中绘制登录框,JS源码
function dis_login() 
{
    document.write("<table width=100% height=90% border=0><tr><td align=center style='font-family: verdana,arial,sans-serif; font-size: 12px ;COLOR: #333333'><DIV class=da_width >"+ 
    "<DIV style='BACKGROUND: url(images/back.jpg); HEIGHT: 214px' id=dl_margin>"+ 
    "<DIV style='font-size: 14px; WIDTH: 280px; MARGIN-TOP: 0px; PADDING-TOP: 25px' align=center><b>"+productInfo+"</b></DIV>"+
    "<DIV style='MARGIN-TOP: 43px; FLOAT: left; WIDTH: 250px' align=right><IMG src='images/h3c_logo.jpg'>&nbsp;</DIV>"+ 
    "<DIV style='HEIGHT: 20px;WIDTH: 480px'></DIV>"+
    "<DIV align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;用户名 <INPUT TabIndex=1 style='BORDER-RIGHT: #87a6c3 1px solid; BORDER-TOP: #87a6c3 1px solid; BACKGROUND: #edeced; BORDER-LEFT: #87a6c3 1px solid; WIDTH: 115px; BORDER-BOTTOM: #87a6c3 1px solid; HEIGHT: 19px' "+
    "id='userName' name='userName' size='16' maxlength='32' onkeypress=\"move(event,'password');if(event.keyCode=='13'){return false;}\"></DIV>");
    if (0 == vldcode_en)
    {
        document.write('<DIV>&nbsp;</DIV>');
    }
    document.write("<DIV align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;密 码 ");
    if (1 == vldcode_en)
    {
        document.write('<input TabIndex=2 id="password" name="password" size="16" maxlength="32" type="password" onkeypress="move(event,\'vldcode\');if(event.keyCode==13){return false;}" ');
    }
    else
    {
        document.write('<input TabIndex=2 id="password" name="password" size="16" maxlength="32" type="password" onkeypress="onEnterSub(event)" ');
    }
    document.write("style='BORDER-RIGHT: #87a6c3 1px solid; BORDER-TOP: #87a6c3 1px solid; BACKGROUND: #edeced; BORDER-LEFT: #87a6c3 1px solid; WIDTH: 115px; BORDER-BOTTOM: #87a6c3 1px solid; HEIGHT: 19px'>");
     
    document.write('<a href=javascript:void(0) onclick=popUserFaq("user_faq.htm?#_Toc286769551")> 忘记密码</a></DIV>');
      
    if (1 == vldcode_en)
    {
        document.write("<DIV align=left>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;验证码 <INPUT TabIndex=3 style='BORDER-RIGHT: #87a6c3 1px solid; BORDER-TOP: #87a6c3 1px solid; BACKGROUND: #edeced; BORDER-LEFT: #87a6c3 1px solid; WIDTH: 115px; BORDER-BOTTOM: #87a6c3 1px solid; HEIGHT: 19px'"); 
        document.write('id="vldcode" name="vldcode" size="16" maxlength="4" type="text" onkeypress="onEnterSub(event)" >');
        document.write('<img id=vldimp src="images/vld.bmp" alt="刷新验证码" onclick=get_vldbmp() style="cursor:pointer"/></DIV>');
    }
    document.write("<span name='messages' id=messages style='HEIGHT:3px; MARGIN-TOP: 0px; MARGIN-LEFT: 20px; WIDTH: 200px; PADDING-TOP: 8px; FLOAT: left;'></span>"+ 
    "<br><br>");
    if (1 == vldcode_en)
    {
        document.write("<DIV style='WIDTH: 80px; MARGIN-TOP: 0px; PADDING-TOP: 12px;'><input TabIndex=4 type='submit' value='  登录  '></DIV>");
    }
    else
    {
        document.write("<DIV style='WIDTH: 80px; MARGIN-TOP: 0px; PADDING-TOP: 20px;'><input TabIndex=3 type='submit' value='  登录  '></DIV>");
    }
     
    document.write("<DIV align=center>&nbsp;</DIV>"+
    "<DIV align=center>推荐分辨率1024*768</DIV>"+
    "<DIV class=lclear></DIV>"+
    "</DIV></DIV></td></tr></table>"); 
}</SCRIPT> 
怎么用java代码登录啦? 有没有什么现成的框架可以使用 或者框架与JS交互的。

解决方案 »

  1.   

    那就等页面生成之后,请求带上参数redirct_index.htm action
      

  2.   

    我查看源代码获取到的东西就是这些,没有变成HTML代码。
      

  3.   

    不管它生成不生成html,最终登陆的是这个form
    <form name="login" action="redirct_index.htm" method="post" onsubmit="return formSubmit2(this);">
    所以你最终的请求就是这个action。哦,还有可能是这个formSubmit2(this);区去分析下这个formSubmit2
      

  4.   


    我把这个提交的JS贴上来。
    function formSubmit2()
    {
        var oUserName = document.getElementById("userName");
        var oPassword = document.getElementById("password");
        if (1 == vldcode_en)
        {
            var oVldcode = document.getElementById("vldcode");
        }    if (0 == oUserName.value.length)
        {
            document.getElementById("messages").innerHTML="请输入用户名!";
            oUserName.focus();
            return false;
        }
        /*
        if (0 == oPassword.value.length)
        {
            document.getElementById("messages").innerHTML="请输入密码!";
            oPassword.focus();
            return false;
        }
        */
        if(!checkStringChar(oPassword,' '))
        {
            document.getElementById("messages").innerHTML="密码不能包含空格!";
            oPassword.focus();
            return false;
        }    oUserName.value = trim(oUserName.value);
        //oPassword.value = trim(oPassword.value);    if (1 == vldcode_en)
        {   
            oVldcode.value  = trim(oVldcode.value);        if ( oVldcode.value == "" )
            {
                document.getElementById("messages").innerHTML="请输入验证码!";
                if (1 == mapOvertime)
                {
                    get_vldbmp();
                }
                else
                {
                    oVldcode.focus();
                }
                return false;
            }
            else if (1 == mapOvertime)
            {
                document.getElementById("messages").innerHTML="验证码已超时,请重新输入!";
                get_vldbmp();
                return false;
            }
            else if (!/(^[a-zA-Z0-9]{4}$)/.test(oVldcode.value)) 
            {
                document.getElementById("messages").innerHTML="验证码错误!";
                return false; 
            }
        }
        
        set_cookie("userName", escape(oUserName.value), null, "/");
        set_cookie("password", oPassword.value, null, "/");
        if (1 == vldcode_en)
        {
            set_cookie("vldcode", oVldcode.value, null, "/");
        }
        
        var d = new Date;
        document.login.rtime.value = (d.getTime() / 500);
        
        return true;
    }
      

  5.   

    js只是生成了form内的用户名、密码等的输入框,这个没有说框架和js交互,什么框架都可以
      

  6.   


    嗯,现在我想登录,一直登录不了。
    try {
    String surl = "http://192.168.0.234/";  
    /** 
     * 首先要和URL下的URLConnection对话。 URLConnection可以很容易的从URL得到。比如: // Using 
     * java.net.URL and //java.net.URLConnection 
     */  
    URL url = new URL(surl);  
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();  
      
    connection.setRequestProperty("User-Agent",
         "Internet Explorer");
    /** 
     * 然后把连接设为输出模式。URLConnection通常作为输入来使用,比如下载一个Web页。 
     * 通过把URLConnection设为输出,你可以把数据向你个Web页传送。下面是如何做: 
     */  
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestMethod("POST");

    /** 
     * 最后,为了得到OutputStream,简单起见,把它约束在Writer并且放入POST信息中,例如: ... 
     */  
    OutputStreamWriter out = new OutputStreamWriter(connection  
            .getOutputStream(), "GBK");  
                  //其中的memberName和password也是阅读html代码得知的,即为表单中对应的参数名称  
    out.write("userName=admin&password=admin"); // post的关键所在!  
    // remember to clean up  
    out.flush();  
    out.close();  

    // 取得cookie,相当于记录了身份,供下次访问时使用  
    String cookieVal = connection.getHeaderField("Set-Cookie");
    System.out.println(cookieVal);

    InputStream urlStream = connection.getInputStream();  
    BufferedReader bufferedReader = new BufferedReader(  
            new InputStreamReader(urlStream));  
    String ss = null;  
    // String total = "";  
    while ((ss = bufferedReader.readLine()) != null) {  
    //     total += ss;  
    System.out.println(ss);
    }  

    bufferedReader.close();  

    } catch (MalformedURLException e) {
    e.printStackTrace();
    } catch (UnsupportedEncodingException e) {
    e.printStackTrace();
    } catch (IOException e) {
    e.printStackTrace();
    }  

    }
      

  7.   

    你那个页面在哪?
    String surl = "http://192.168.0.234/.../redirct_index.htm"
      

  8.   


    页面 就是这个,“http://192.168.0.234”登录进去就可以看到里面的菜单页面了。
      

  9.   


    redirct_index.htm 是负责跳转的页面,会跳转到首页去。
      

  10.   

    String surl = "http://192.168.0.234/redirct_index.htm" 
    用这个事实页面 就是这个,“http://192.168.0.234”登录进去就可以看到里面的菜单页面了。
      

  11.   


    页面 就是这个,“http://192.168.0.234”登录进去就可以看到里面的菜单页面了。后面要跟action么?
      

  12.   


    页面 就是这个,“http://192.168.0.234”登录进去就可以看到里面的菜单页面了。String url = http://192.168.0.234/redirct_index.htmout.write("userName=admin&password=admin"); // post的关键所在!  我现在的代码。这句代码中是不是要添加什么东西?
      

  13.   


    页面 就是这个,“http://192.168.0.234”登录进去就可以看到里面的菜单页面了。你说的基本上是正确的,直接提交到redirct_index.htm中就可以,但是form中表单中有个onsubmit属性,这个属性阻止了我的表单提交。请问这个情况怎么处理啊?