Answer the question
In order to leave comments, you need to log in
How to run servlet on vps?
Hello, I decided that learning Java would be more productive and enjoyable on a VPS, and I ran into a problem that I can’t find a solution to. In fact, the problem is not complicated, but I'm missing something, help, please.
There is a VPS (ubuntu), it has tomcat7 and nginx. The /var/lib/tomcat7/webapps/simple folder contains the project itself. /var/lib/tomcat7/webapps/simple/WEB-INF/classes/Servlets contains the file
MyServlet.java after clicking on it, it redirects to the myServlet page with a 404 error. On the local machine (win8) everything works. Do I need to compile anything at all before running it on the server? Maybe I misconfigured something?
servlet listing MyServlet.java
package Servlets;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
public class MyServlet extends HttpServlet {
public void doGet(HttpServletResponse response,
HttpServletRequest) throws IOException, ServletException {
response.setContentType("text/html");
response.setStatus(HttpServletResponse.SC_OK);
PrintWriter out = response.getWriter();
out.write("<h1>Hello!</h1>");
out.flush();
out.close();
}
}
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>Servlets.MyServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myServlet</servlet-name>
<url-pattern>/myservlet</url-pattern>
</servlet-mapping>
Answer the question
In order to leave comments, you need to log in
Everything worked.
Perhaps someone will need to configure nginx to work with apache and tomcat servers... ;
And a description of the creation of the Java Server-Side Programming project
I have a suspicion that you do not know about WAR archives.
WAR
stackoverflow.com/questions/5108019/how-to-make-wa...
stackoverflow.com/questions/5109112/how-to-deploy-...
PS: .java files are not executable - they are just a text file on the basis of which the executable code is compiled - files with the .class extension.
Yes, and packages are usually called with a small letter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question