authcode java_java - 如何将我的authCode变量从我的JSP传递到Java类以在HTTP调用中使用? - 堆栈内存溢出...

我试图将java类与JSP结合使用。 当服务器启动时,用户转到JSP,它将它们重定向到第三方的身份验证表单。 在身份验证流程之后,他们可以填写他们的信息,按提交,并将该信息发送到HTTP帖子中的服务器。 我遇到的问题是将变量从我的JSP传递给我的java类。 我怀疑我可能需要使用一个servlet,但是我想在将它们全部移动到servlet之前看看是否有办法只使用Java类/ bean。 我知道我可能要调用变量,但我不知道该怎么做。 任何答案或建议都会非常有帮助! 我是一个编码的初学者,但我真的想让这个小应用程序运行起来。 谢谢!

serverFlow.java

public class serverFlow {

public StringBuffer getAccessToken(String redirectUri, String clientId, String clientSecret, String authCode)

throws IOException {

// Define base URL

String baseUrl = "https://idfed.constantcontact.com/as/token.oauth2";

// Build URL

String fullUrl = baseUrl + "?code=" + authCode + "&redirect_uri=" + redirectUri

+ "&grant_type=authorization_code&scope=contact_data";

URL authorizeUrl = new URL(fullUrl);

// Open connection

HttpURLConnection con = (HttpURLConnection) authorizeUrl.openConnection();

// Encode Auth Info

String credentials = clientId + ":" + clientSecret;

String auth = "Basic " + Base64.getEncoder().encodeToString(credentials.getBytes());

// Post Method for CTCT request

con.setRequestMethod("POST");

// Add Headers

con.setRequestProperty("Authorization", auth);

// Open input steam

BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));

String inputLine;

StringBuffer result = new StringBuffer();

// Append each line

while ((inputLine = in.readLine()) != null) {

result.append(inputLine);

}

// Close the stream

in.close();

return result;

}

public static void main(String[] args){

serverFlow server = new serverFlow();

// Print string buffered response of access token, refresh token and authentication type

// Attempted to use a reqeust but unable to utilize 'reqeust.' is there a way to get the authCode in this Java class from my JSP?

System.out.println(server.getAccessToken("http%3A%2F%2Flocalhost%3A8080%2Fsignup", clientId, clientSecret, authCode));

}

}

signup.jsp

My Jmml

Contact Information

%>

// This is where the authCode is generated, how do I get this back over to my serverFlow.jsp?

String authCode = "";

try {

authCode = request.getParameter("code");

request.setAttribute("authCode", authCode);

// Verifies it in console

System.out.println("Here is the auth code: " + authCode);

}catch(Exception a){

System.out.println("Could not get Auth Code: " + a);

}

}%>

Email Address

}%>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值