简体   繁体   中英

Why can't i see my ${token} in my jsp?

I have been having a problem while trying to pass a variable to a JSP. This is my servlet code:

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);
    }
}

And, this is my client.jsp file:

<!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 is from this tutorial .

I am accessing my page through the following URL:

http://localhost:8080/TwillioTest1/TwilioServlet

Why isn't ${token} being replaced?

Possible answer to your problem - click . Don't be afraid to use the power of Google.

Update

As suggested by @dur I include part of answer from link here:

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>

EL expressions may be disabled; you may have to activate them in your web.xml. Can you try this?

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