如何以编程方式登录j_security_check [英] How to programatically login to j_security_check
本文介绍了如何以编程方式登录j_security_check的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用 j_security_check
的JSP Web应用程序。如果我知道用户名和密码,是否可以通过JSP页面以编程方式将特定用户登录到 j_security_check
?我试图以这种方式将变量作为URL参数传递...
I have a JSP web application which uses j_security_check
. Is it possible to login a specific user to j_security_check
programatically via a JSP page if I know the userid and password? I tried to pass the variables as URL parameters this way...
response.sendRedirect(www.mydomain.com/j_security_check?j_username=someUserName&j_password=somePassword )
...但它不起作用。有没有办法做到这一点?
...but it doesnt work. Is there any way to do it?
编辑:
这里是我的登录页面,现在可以正常工作。出于安全原因,我修剪了一些代码。
here is my login page which works fine right now. I trimmed some of the code for security reasons.
<form name="signon" method="post" action="/j_security_check">
<table width="100%" cellpadding="4" cellspacing="0">
<tr>
<td valign="top" colspan="4">
<h2><%= UI.tr(null, "login_details") %>
</h2>
</td>
</tr>
<tr>
<td valign="top" width="150px">
<%= UI.tr(null, "login_id") %>
</td>
<td valign="top" width="150px">
<%= UI.tr(null, "login_pass") %>
</td>
<td valign="top" width="150px">
<%= UI.tr(null, "login_token_or_captcha") %>
</td>
<td width="100%"> </td>
</tr>
<tr>
<%
if (logins == null) {
%>
<td>
<input type="hidden" name="j_uri" value="/index.jsp">
<input type="text" id="username" name="j_username" size="16" style="width: 150px;" autocomplete="off" <%= username == null ? "" : "disabled value='" + username + "'" %> onblur="return checkCaptcha();">
</td>
<%
} else {
%>
<td>
<select name="j_username" style="width: 150px;">
<%
for (Login login : logins) {
%>
<option><%= login.getUsername() %>
</option>
<%
}
%>
</select>
</td>
<%
}
%>
<td><input type="password" name="j_password" size="16" style="width: 150px;"> </td>
<td><input type="text" id="mypw" name="mypw" size="16" autocomplete="off" style="width: 150px;"></td>
<td><input class="submit" type="submit" name="submit" value="<%= UI.tr(null, "login_submit") %>"></td>
</tr>
<tr>
<td valign="top" colspan="4">
<%-- <%
if("registry.nic.hn".equals(request.getServerName())) {
%>
<!-- GARTH - put whatever you want here for .HN -->
<% } else { %> --%>
<h2><%= UI.tr(null, "login_news") %>
</h2>
<div><%= HTMLFormat.addBreaks(SiteConf.getSiteConf().getNews()) %>
</div>
<%-- <% } %> --%>
</td>
</tr>
推荐答案
以下代码适用于JSP文件:
The following code works for me in the JSP file:
String url = "j_security_check?j_username=" + username + "&j_password=" + password;
String redirectUrl = response.encodeRedirectURL(url);
response.sendRedirect(redirectUrl);
这篇关于如何以编程方式登录j_security_check的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文