Running JSP files with tomcat 7

老子叫甜甜 提交于 2021-02-04 14:12:52

问题


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.

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>

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

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

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!

Thanks in advance for any help!


回答1:


Your JSP file must NOT be in WEB-INF.

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 is where you put the files that you don't want to make accessible from the outside:

  • 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).

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




回答2:


Rename your jsp-file to:

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\index.jsp

now, navigate to

http://localhost:8089/

Short and Easy.




回答3:


Put your jsp file in ROOT folder as

/Users/<username>/Desktop/tomcat/webapps/ROOT/test.jsp

Run your application like

http://localhost:8080/test.jsp




回答4:


Save your jsp file in your webapps directory with .jsp extention

C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps and types at the address bar of the browser- http:\localhost:8089/exmp.jsp and press Enter key



来源:https://stackoverflow.com/questions/13877797/running-jsp-files-with-tomcat-7

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!