下面我有一个非常简单的例子来说明我想要做的事情。我的Java类"CommonUtils“有一个加密和解密字符串的方法。在将它们写入cookie之前,我想对logonuidfield和logonpassfield进行加密。我知道直接从Javascript调用CommonUtils.xorEncode(~)是不可能的,但是是否有可能在编写cookie之前通过CommonUtils.xorEncode(~)传递这些字段的值?
我不希望用javascript编写加密方法。我希望它在Java类中。我猜想,如果不使用LiveConnect或其他类似的东西,我就不可能做什么。
提前谢谢。
<%@ page import="package.CommonUtils" %>
<HTML>
<SCRIPT LANGUAGE=JavaScript>
function setCookies() {
var email = document.getElementById("logonuidfield").value;
var password = document.getElementById("logonpassfield").value;
writeCookie("EmailText",email);
writeCookie("PasswordText",password);
}
function writeCookie(name, value) {
document.cookie = name + "=" + escape(value);
}
</script>
<body>
<tr>
<td>
<%
String message = "This is a test message.";
out.println("<Label>This is the original message: " + message + "</Label><br>");
out.println("<Label>Hex before encrypting : " + CommonUtils.printStringHex(message) + "</Label><br>");
message = CommonUtils.xorEncode(message);
out.println("<Label>Hex after encrypting : " + CommonUtils.printStringHex(message) + "</Label><br>");
message = CommonUtils.xorDecode(message);
out.println("<Label>Hex after decrypting : " + CommonUtils.printStringHex(message) + "</Label><br>");
out.println("<Label>This is the final message : " + message + "</Label><br>");
%>
</td>
</tr>
<FORM name="logonForm" id="logonForm" autocomplete="off" onsubmit="setCookies()" method="post" action="" >
<li>
<input type="text" id="logonuidfield" placeholder="email address*" style="width: 100%" name="j_user" type="email" value="" title="Email address *"/>
</li>
<li>
<input type="password" id="logonpassfield" placeholder="Password*" style="width: 100%" name="j_password" />
</li>
<li>
<input type="submit" value="Log in" name="uidPasswordLogon"/>
</li>
</form>发布于 2013-06-26 13:29:45
请注意您的请求/响应周期:
所以,您不能只在第4步的服务器端执行一些java加密,因为直到第7步才能得到答案。
也许我们需要更多关于你想做的事情的具体信息.
https://stackoverflow.com/questions/17320854
复制相似问题