[英]How To Add A Variable To The Url Of A JSP Page
我创建了一个使用Spring Social链接到Facebook的程序。 它会加载一个JSP登录页面,然后重定向到我的应用程序页面。 登录页面的URL为http://localhost:8080/my-app/signin
。 单击“登录”按钮后,它将重定向到http://localyhost:8080/my-app/#_=_
。 我想发生的是,当它在url末尾重定向主页时,我想添加一个包含唯一数字的变量。 所以我希望它看起来像http://localhost:8080/my-app/1234567
而不是http://localhost:8080/my-app/#_=_.
我感谢您的帮助。
登录页面
<%@ page session="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Sign In</title>
</head>
<body>
<form action="<c:url value="/signin/facebook" />" method="POST">
<button type="submit">Sign in with Facebook</button>
<input type="hidden" name="scope" value="email,publish_stream,offline_access" />
</form>
</body>
</html>
主页
<%@ page session="false" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title>Home</title>
</head>
<body>
<ul>
<li><a href="<c:url value="/signout" />">Sign Out</a></li>
</ul>
<p>${number}</p>
<h3>Your Facebook Friends</h3>
<ul>
<c:forEach items="${friends}" var="friend">
<li><img src="http://graph.facebook.com/<c:out value="${friend.id}"/>/picture" align="middle"/><c:out value="${friend.name}"/></li>
</c:forEach>
</ul>
</body>
</html>
家庭控制器
@RequestMapping(value = "/", method = RequestMethod.GET)
public String home(Model model) throws IOException {
List<Reference> friends = facebook.friendOperations().getFriends();
FacebookProfile profile = facebook.userOperations().getUserProfile();
String userID = facebook.userOperations().getUserProfile().getId();
model.addAttribute("friends", friends);
String accessToken = connectionRepository.getPrimaryConnection(Facebook.class).createData().getAccessToken();
System.out.println(accessToken);
return "home";
}
基本上,似乎您想在单击“登录”按钮时更改表单的提交URL。
由于单击按钮是在客户端站点上发生的事情,因此您将需要一个Java脚本,该脚本将在登录按钮的click事件中调用,采用jsp的form元素并将其提交URL修改为所需的URL。 。
如果您正在寻找的是,下面的链接应该可以为您提供帮助,就像在正确的Google搜索中提供的类似链接一样:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.