java登录由JS 生成的页面

大_爱 2013-11-12 10:22:51
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'> </DIV>"+
"<DIV style='HEIGHT: 20px;WIDTH: 480px'></DIV>"+
"<DIV align=left>      用户名 <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> </DIV>');
}
document.write("<DIV align=left>      密 码 ");
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>      验证码 <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> </DIV>"+
"<DIV align=center>推荐分辨率1024*768</DIV>"+
"<DIV class=lclear></DIV>"+
"</DIV></DIV></td></tr></table>");
}

</SCRIPT>


怎么用java代码登录啦? 有没有什么现成的框架可以使用 或者框架与JS交互的。
...全文
354 23 打赏 收藏 转发到动态 举报
写回复
用AI写文章
23 条回复
切换为时间正序
请发表友善的回复…
发表回复
大_爱 2013-11-12
  • 打赏
  • 举报
回复
这个还有图片验证,坑爹啊
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 4 楼 huxiweng 的回复:
不管它生成不生成html,最终登陆的是这个form <form name="login" action="redirct_index.htm" method="post" onsubmit="return formSubmit2(this);"> 所以你最终的请求就是这个action。哦,还有可能是这个formSubmit2(this);区去分析下这个formSubmit2
我把这个提交的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;
}

大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 5 楼 whz137458 的回复:
代码写得好邪恶!!!
这个代码不是我写的,我是在搞人家的代码!
tony4geek 2013-11-12
  • 打赏
  • 举报
回复
和正常登录一样吧。你浏览器调试工具应该可以看到生成的代码。源文件没有。
rome_wu 2013-11-12
  • 打赏
  • 举报
回复
代码写得好邪恶!!!
teemai 2013-11-12
  • 打赏
  • 举报
回复
不管它生成不生成html,最终登陆的是这个form <form name="login" action="redirct_index.htm" method="post" onsubmit="return formSubmit2(this);"> 所以你最终的请求就是这个action。哦,还有可能是这个formSubmit2(this);区去分析下这个formSubmit2
大_爱 2013-11-12
  • 打赏
  • 举报
回复
我查看源代码获取到的东西就是这些,没有变成HTML代码。
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 1 楼 huxiweng 的回复:
那就等页面生成之后,请求带上参数redirct_index.htm action
、板子能说的明白些了,不是太懂。
teemai 2013-11-12
  • 打赏
  • 举报
回复
那就等页面生成之后,请求带上参数redirct_index.htm action
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 18 楼 huxiweng 的回复:
String surl = "http://192.168.0.234/redirct_index.htm" 用这个事实 [quote=引用 16 楼 beefcattlexiaoyang 的回复:] [quote=引用 15 楼 huxiweng 的回复:] 你那个页面在哪? String surl = "http://192.168.0.234/.../redirct_index.htm"
页面 就是这个,“http://192.168.0.234” 登录进去就可以看到里面的菜单页面了。[/quote][/quote] 你说的基本上是正确的,直接提交到redirct_index.htm中就可以,但是 form中表单中有个onsubmit属性,这个属性阻止了我的表单提交。 请问这个情况怎么处理啊?
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 18 楼 huxiweng 的回复:
String surl = "http://192.168.0.234/redirct_index.htm" 用这个事实 [quote=引用 16 楼 beefcattlexiaoyang 的回复:] [quote=引用 15 楼 huxiweng 的回复:] 你那个页面在哪? String surl = "http://192.168.0.234/.../redirct_index.htm"
页面 就是这个,“http://192.168.0.234” 登录进去就可以看到里面的菜单页面了。[/quote][/quote] String url = http://192.168.0.234/redirct_index.htm out.write("userName=admin&password=admin"); // post的关键所在! 我现在的代码。 这句代码中是不是要添加什么东西?
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 18 楼 huxiweng 的回复:
String surl = "http://192.168.0.234/redirct_index.htm" 用这个事实 [quote=引用 16 楼 beefcattlexiaoyang 的回复:] [quote=引用 15 楼 huxiweng 的回复:] 你那个页面在哪? String surl = "http://192.168.0.234/.../redirct_index.htm"
页面 就是这个,“http://192.168.0.234” 登录进去就可以看到里面的菜单页面了。[/quote][/quote] 后面要跟action么?
teemai 2013-11-12
  • 打赏
  • 举报
回复
String surl = "http://192.168.0.234/redirct_index.htm" 用这个事实
引用 16 楼 beefcattlexiaoyang 的回复:
[quote=引用 15 楼 huxiweng 的回复:] 你那个页面在哪? String surl = "http://192.168.0.234/.../redirct_index.htm"
页面 就是这个,“http://192.168.0.234” 登录进去就可以看到里面的菜单页面了。[/quote]
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 15 楼 huxiweng 的回复:
你那个页面在哪? String surl = "http://192.168.0.234/.../redirct_index.htm"
redirct_index.htm 是负责跳转的页面,会跳转到首页去。
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 15 楼 huxiweng 的回复:
你那个页面在哪? String surl = "http://192.168.0.234/.../redirct_index.htm"
页面 就是这个,“http://192.168.0.234” 登录进去就可以看到里面的菜单页面了。
teemai 2013-11-12
  • 打赏
  • 举报
回复
你那个页面在哪? String surl = "http://192.168.0.234/.../redirct_index.htm"
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 13 楼 huxiweng 的回复:
[quote=引用 12 楼 beefcattlexiaoyang 的回复:] [quote=引用 4 楼 huxiweng 的回复:] 不管它生成不生成html,最终登陆的是这个form <form name="login" action="redirct_index.htm" method="post" onsubmit="return formSubmit2(this);"> 所以你最终的请求就是这个action。哦,还有可能是这个formSubmit2(this);区去分析下这个formSubmit2
版主帮忙看看上面的代码,是这样跟参数么?[/quote] 好像还有个验证码,这个比较麻烦。需要识别验证码的。。。[/quote] 我把验证码的功能去掉了,只需要用户名和密码就可以了。 我上面写了点代码,但是还是登录不了,返回401错误
teemai 2013-11-12
  • 打赏
  • 举报
回复
引用 12 楼 beefcattlexiaoyang 的回复:
[quote=引用 4 楼 huxiweng 的回复:] 不管它生成不生成html,最终登陆的是这个form <form name="login" action="redirct_index.htm" method="post" onsubmit="return formSubmit2(this);"> 所以你最终的请求就是这个action。哦,还有可能是这个formSubmit2(this);区去分析下这个formSubmit2
版主帮忙看看上面的代码,是这样跟参数么?[/quote] 好像还有个验证码,这个比较麻烦。需要识别验证码的。。。
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 4 楼 huxiweng 的回复:
不管它生成不生成html,最终登陆的是这个form <form name="login" action="redirct_index.htm" method="post" onsubmit="return formSubmit2(this);"> 所以你最终的请求就是这个action。哦,还有可能是这个formSubmit2(this);区去分析下这个formSubmit2
版主帮忙看看上面的代码,是这样跟参数么?
大_爱 2013-11-12
  • 打赏
  • 举报
回复
引用 10 楼 cheng417905 的回复:
js只是生成了form内的用户名、密码等的输入框,这个没有说框架和js交互,什么框架都可以
嗯,现在我想登录,一直登录不了。

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();
		}  
		
	}

加载更多回复(1)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧