春季安全登录表单这是 login.jsp 即http://localhost:8082/Spring-MVC/login.jsp
<form name='f' action="<c:url value='j_spring_security_check' />"
method='POST'>
<table>
<tr>
<td>User:</td>
<td><input type='text' name='j_username' value=''>
</td>
</tr>
<tr>
<td>Password:</td>
<td><input type='password' name='j_password' />
</td>
</tr>
<tr>
<td colspan='2'><input name="submit" type="submit"
value="submit" />
</td>
</tr>
<tr>
<td colspan='2'><input name="reset" type="reset" />
</td>
</tr>
</table>
</form>
JSP代码相当于上面的post表单方法,
<% HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod("http://localhost:8082/SpringMVC/j_spring_security_check");
postMethod.addParameter("j_username", "mkyong");
postMethod.addParameter("j_password", "123456");
try {
httpClient.executeMethod(postMethod);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
if (postMethod.getStatusCode() == HttpStatus.SC_OK) {
String resp = postMethod.getResponseBodyAsString();
} else {
//...postMethod.getStatusLine();
}
%>
实际上,我认为两者的结果相同,但在第二种情况下,通过使用 post 方法,它不会将我重定向到主页。我想使用 httpclient 代码自动提交上述表单。请帮帮我