使用tomcat 7运行JSP文件 [英] Running JSP files with tomcat 7

查看:93
本文介绍了使用tomcat 7运行JSP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚安装了Apache Tomcat 7,并使服务器运行正常.当我输入localhost:8089(8089是我分配给Tomcat 7的端口)时,弹出了apache网站,我运行了一些jsp示例,它们可以正确打开.

Hi I just installed Apache Tomcat 7 and got the server running OK. When I entered localhost:8089 (8089 being the port I assigned to Tomcat 7) the apache website popped up and I got to run some jsp examples and they opened correctly.

但是,现在我希望自己创建一个jsp文件(这是我第一次尝试教程),当我打开它们时,浏览器中仅显示我编写的源代码.

However now I wish to create a jsp file myself (I am trying tutorials for the very first time) and when I open them, only the source code I written is showing in the browser.

我正在尝试的示例是这样:

The example I am trying is this:

<html>
<head>
</head>

<body>
Hello World. <%= new java.util.Date() %>
</body>

</html>

我在Chrome浏览器中看到的全部是:"Hello World. <%= new java.util.Date() %>"

and all I'm seeing in Chrome is : "Hello World. <%= new java.util.Date() %>"

我正在此文件中保存此文件:

I am saving this file in this path:

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\host-manager\WEB-INF\jsp

在WEB-INF中,已经准备好一个index.html文件.

In WEB-INF there is an index.html file ready.

我做错什么了吗?我应该在哪里保存文件? 我曾尝试在youtube上观看教程,但其中大多数都是阿拉伯语的,我听不懂!

Am I doing something wrong? Where am I supposed to save my file? I tried watching tutorials on youtube but most of them were in arabic and I couldn't understand a thing!

在此先感谢您的帮助!

推荐答案

您的JSP文件不得位于WEB-INF中.

Your JSP file must NOT be in WEB-INF.

您必须创建一个您想要命名的目录(例如,myFirstWebApp),将您的JSP放置在您想要的除WEB-INF之外的任何子目录中(例如,myFirstWebApp/foo/bar/hello.jsp),然后通过将myFirstWebApp目录复制到以下位置来部署Webapp: Tomcat的webapps目录.然后可以使用URL来访问JSP

You must create a directory named as you want (myFirstWebApp for example), put your JSP in any subdirectory you want except WEB-INF (for example myFirstWebApp/foo/bar/hello.jsp), then deploy the webapp by copying the myFirstWebApp firectory to the webapps directory of Tomcat. The JSP will then be accessible using the URL

http://localhost:8089/myFirstWebApp/foo/bar/hello.jsp

在WEB-INF中,您可以放置​​不需要从外部访问的文件:

WEB-INF is where you put the files that you don't want to make accessible from the outside:

  • 罐子(在WEB-INF/lib下),
  • 类(在WEB-INF/classes下),
  • 部署描述符(web.xml,在通过注释配置的servlet 3.0 webapps中为可选),
  • 以及您想要在WEB-INF下的任何其他文件(通常是配置文件).
  • the jars (under WEB-INF/lib),
  • the classes (under WEB-INF/classes),
  • the deployment descriptor (web.xml, optional in servlet 3.0 webapps configured through annotations),
  • and any other file you want anywhere under WEB-INF (typically, configuration files).

为什么不阅读文档? http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html

Why don't you read the documentation? http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html

这篇关于使用tomcat 7运行JSP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆