简体   繁体   中英

JSP wouldn't compile

<HTML>
<BODY>
Hello!  The time is now <%= new java.util.Date() %>
</BODY>
</HTML>

I tried to open this trivial jsp file with firefox, but the expression wouldn't evaluate. I have Java installed.

I'm new to JSP. Should I put the jsp in some specific directory? Or do I forget to include anything in the jsp file?

It sounds like that you aren't using a JSP/Servlet container at all but instead just opened the file straight from local disk file system by a file:// URL. This is indeed not going to work. You need to install a JSP/Servlet container. This is basically a HTTP web server which has the JSP compiler builtin and supports serving JSP/Servlets. A well known example is Apache Tomcat . Just download the zip under "Core" section (no, not the "Windows zip", really just "zip") and extract it on your disk. Then perform the following steps:

  1. Create a new subfolder in /webapps folder of Tomcat.
  2. Put the JSP file in that folder.
  3. Start Tomcat by the /bin/startup.bat (Windows) or /bin/startup.sh (Unix) script.
  4. Go in your browser to http://localhost:8080/foldername/yourfile.jsp where "foldername" is the name of the folder you created in step 1 and "yourfile.jsp" is the filename of the JSP you placed in step 2.

See also:

A JSP is evaluated by a web container like Tomcat or Jetty, and the HTML that it generates is then sent to the browser. The browser can't run a JSP on its own.

检查您的项目库设置,并且您的Java库位于PATH类中。

Each jsp page must be compiled to a servlet by a JSP engine. Firefox is not a JSP engine. Have a look at JavaServer Pages Technology which might be helpful to you.

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