[英]Why can't i see my ${token} in my jsp?
嘗試將變量傳遞給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>
這是本教程的內容 。
我正在通過以下URL訪問頁面:
http://localhost:8080/TwillioTest1/TwilioServlet
為什么不替換${token}
?
您的問題的可能答案- 單擊 。 不要害怕使用Google的功能。
更新資料
正如@dur所建議的那樣,我在此處包含了部分鏈接的答案:
從web.xml中刪除該DOCTYPE,一切應該很好。 有效的Servlet 3.0(Tomcat 7,JBoss AS 6/7,GlassFish 3等)兼容的web.xml整體如下所示,沒有任何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>
EL表達式可能被禁用; 您可能需要在web.xml中激活它們。 你可以試試這個嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.