How do I host a java file using Apache Tomcat in xampp? - Stack Overflow

I downloaded xampp and java. I compiled a java program, added it to the directory(C:xampptomcatwebap

I downloaded xampp and java. I compiled a java program, added it to the directory(C:\xampp\tomcat\webapps\ROOT\WEB-INF/StinkyApp.class), and opened localhost:8080 in my browser.

But I got an error message saying HTTP Status 404 – Not Found Type Status Report

Message The requested resource /webapps/StinkyApp.class is not available

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.96 Can someone help me with this?

I downloaded xampp and java. I compiled a java program, added it to the directory(C:\xampp\tomcat\webapps\ROOT\WEB-INF/StinkyApp.class), and opened localhost:8080 in my browser.

But I got an error message saying HTTP Status 404 – Not Found Type Status Report

Message The requested resource /webapps/StinkyApp.class is not available

Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.

Apache Tomcat/8.5.96 Can someone help me with this?

Share Improve this question asked 16 hours ago user30097622user30097622 1 New contributor user30097622 is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 3

Tomcat expects Java class files (like servlets and other classes) under the WEB-INF\classes directory.

If its a servelet class, you should move your compiled .class file into the following directory and map it with servlet tags in web.xml

C:\xampp\tomcat\webapps\ROOT\WEB-INF\classes\StinkyApp.class

After placing your class there, restart your Tomcat server and try accessing it.

Instead of using ROOT app, you can create your own application under webapps like below and try.

webapps/
└── StinkyApp/
    ├── WEB-INF/
    │   ├── classes/
    │   │   └── StinkyApp.class
    │   └── web.xml

update your web.xml and add the below if the class is a servlet and restart the tomcat server.

<web-app xmlns="http://xmlns.jcp./xml/ns/javaee"
         xmlns:xsi="http://www.w3./2001/XMLSchema-instance"
         xsi:schemaLocation="http://xmlns.jcp./xml/ns/javaee
         http://xmlns.jcp./xml/ns/javaee/web-app_3_1.xsd"
         version="3.1">

    <servlet>
        <servlet-name>StinkyServlet</servlet-name>
        <servlet-class>StinkyApp</servlet-class>
    </servlet>

    <servlet-mapping>
        <servlet-name>StinkyServlet</servlet-name>
        <url-pattern>/stinky</url-pattern>
    </servlet-mapping>

</web-app>

and access the application with : http://localhost:8080/StinkyApp/stinky

of if you want to try the tomcat is working or not you can create a simple html under StinkyApp and access it with : http://localhost:8080/StinkyApp

webapps/
└── StinkyApp/
    ├── index.html
    ├── WEB-INF/
    │   ├── classes/
    │   │   └── StinkyApp.class
    │   └── web.xml

index.html

<!DOCTYPE html>
<html>
<head>
    <title>Hello JSP</title>
</head>
<body>
    <h1>Hello World!</h1>
</body>
</html>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1743758010a4502112.html

相关推荐

  • How do I host a java file using Apache Tomcat in xampp? - Stack Overflow

    I downloaded xampp and java. I compiled a java program, added it to the directory(C:xampptomcatwebap

    6天前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信