gpt4 book ai didi

java - 为什么我在 jsp 中看不到我的 ${token} ?

转载 作者:行者123 更新时间:2023-12-01 09:37:42 25 4
gpt4 key购买 nike

我在尝试将变量传递给 JSP 时遇到问题。这是我的 servlet 代码:

public class TwilioServlet extends HttpServlet {

private static final long serialVersionUID = 3645708904327108592L;
public static final String ACCOUNT_SID = "account_sid";
public static final String AUTH_TOKEN = "auth_token";
public static final String APP_SID = "app_sid";

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {

TwilioCapability capability = new TwilioCapability(ACCOUNT_SID, AUTH_TOKEN);
capability.allowClientOutgoing(APP_SID);

String token = null;
try {
token = capability.generateToken();
} catch (DomainException e) {
e.printStackTrace();
}
// Forward the token information to a JSP view
response.setContentType("text/html");
request.setAttribute("token", token);
System.out.println("Capability toke is " + token);
RequestDispatcher view = request.getRequestDispatcher("client.jsp");
view.forward(request, response);
}
}

这是我的 client.jsp 文件:

<!DOCTYPE html>
<html>
<head>
<title>Hello Client Monkey 1</title>
<script type="text/javascript"
src="//media.twiliocdn.com/sdk/js/client/v1.3/twilio.min.js"></script>
<script type="text/javascript"
src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js">
</script>
<link href="//static0.twilio.com/resources/quickstart/client.css"
type="text/css" rel="stylesheet" />
<script type="text/javascript">

/* Create the Client with a Capability Token */
Twilio.Device.setup("${token}", {debug: true});

/* Let us know when the client is ready. */
Twilio.Device.ready(function (device) {
$("#log").text("Ready");
});

/* Report any errors on the screen */
Twilio.Device.error(function (error) {
$("#log").text("Error: " + error.message);
});

Twilio.Device.connect(function (conn) {
$("#log").text("Successfully established call");
});

/* Connect to Twilio when we call this function. */
function call() {
Twilio.Device.connect();
}
</script>
</head>
<body>
<button class="call" onclick="call();">Call</button>

<div id="log">Loading pigeons...</div>
</body>
</html>

这是来自 this tutorial .

我通过以下 URL 访问我的页面:

http://localhost:8080/TwillioTest1/TwilioServlet

为什么${token}没有被替换?

最佳答案

您的问题的可能答案 - click 。不要害怕使用 Google 的力量。

更新

根据@dur的建议,我在此处包含了链接中的部分答案:

Remove that DOCTYPE from web.xml and all should be well. A valid Servlet 3.0 (Tomcat 7, JBoss AS 6/7, GlassFish 3, etc) compatible web.xml look like below in its entirety, without any DOCTYPE:

<?xml version="1.0" encoding="UTF-8"?>
<web-app
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
</web-app>

关于java - 为什么我在 jsp 中看不到我的 ${token} ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38719278/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com