简体   繁体   中英

How To Add A Variable To The Url Of A JSP Page

Im creating a program that links to facebook using Spring Social. It loads this a JSP sign in page which then redirects to my apps page. The url of the log in page is http://localhost:8080/my-app/signin . After clicking the log in button it redirects to http://localyhost:8080/my-app/#_=_ . What i want to happen is that when it redirects the the home page at the end of the url i would like to add a variable that contains a unique number. so i would like it to look like http://localhost:8080/my-app/1234567 instead of http://localhost:8080/my-app/#_=_. I appreciate your help.

Sign In Page

<%@ 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>

Home Page

<%@ 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>

Home Controller

@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";
    }

Basically it seems you want to change the submit URL of the form when log in button is clicked.

Since click of a button is something that would happen on client site, you will need a java script which will be called on the click event of log in button, take the form element of the jsp and modify its submit URL to the URL you want.

If that is what you are looking for, the link below should help as would similar links on proper Google search:

sample

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM