First of all, let me tell that I never did any program of Java, but now I need to a very simple test on a Weblogic 14C that was installed to use Java 11
So, as I'm not a Java programer at all I asked ChatGPT to create one for me, and the code generated was
import java.io.IOException;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/current-time")
public class CurrentTimeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
// Get current server time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date now = new Date();
String currentTime = sdf.format(now);
// Write HTML response
out.println("\<html>");
out.println("\<head>\<title>Current Server Time\</title>\</head>");
out.println("\<body>");
out.println("\<h1>Current Server Time:\</h1>");
out.println("\<p>" + currentTime + "\</p>");
out.println("\</body>");
out.println("\</html>");
out.close();
}
}
The instruction to generate the .war was:
javac -cp $WEBLOGIC_HOME/server/lib/weblogic.jar CurrentTimeServlet.java
jar cvf CurrentTimeApp.war CurrentTimeServlet.class
and deploy to weblogic, which I did, however when I call http://myserver:port/CurrentTimeApp/current-time I'm getting error 404 page not found
Here is the big thing: I know that by default people use web.xml and weblogic.xml as configuration file, however according to ChatGpt with the new Java the web.xml is not necessary anymore (even still can be used for compatibility purpose),
What I want to do is make the program run WITHOUT creating the web.xml … seems the parte of the code where it says @WebServlet("/current-time") , should make the web.xml uncessary
What Am I missing?