T
T
Timur Sergeevich2016-01-29 18:26:22
Java
Timur Sergeevich, 2016-01-29 18:26:22

How to specify path to JSP?

I understand that most of the answers on the topic html css js and php are unlikely to be answered here (But little is here ru.stackoverflow.com/questions/487393/%D0%9A%D0%B0...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
goshan_p, 2016-01-29
@goshan_p

Watching what you are using. If Spring, then the prefix and suffix are specified in the configuration. And in the controller, only the name of the view. If Java EE, then in web.xml . Judging by the project in the screenshot. You need to create a web.xml and organize your project structure properly.

B
bromzh, 2016-01-29
@bromzh

What is the rubbish in the project? Learn maven, see what structure a standard Maven project has.
If you use Jetty, then you can do this (provided that your project structure is normal, and not like right now):
1) Create a folder in the src/main/resources folder named webapp, for example
2)

// Application.java
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;

import javax.servlet.Servlet;

class Application implements Runnable {
    Server server;
    ServletContextHandler handler;

    public Application() {
        server = new Server(8080);
        handler = new ServletContextHandler(ServletContextHandler.SESSIONS);
        server.setHandler(handler);
    }

    @Override
    void run() {
        try {
            server.start();
            server.join();
        } finally {
            server.destroy();
        }
    }

    void addServlet(String path, Servlet servlet) {
        handler.addServlet(new ServletHolder(servlet), path);
    }

    void addServlet(String path, Class<? extends Servlet> servletClass) {
        handler.addServlet(new ServletHolder(servletClass), path);
    }
}

// Main.java
import org.eclipse.jetty.servlet.DefaultServlet;

public class Main {
    public static void main(String args[]) {
        Application app = new Application();

        app.handler.setContextPath("/");
        app.handler.setResourceBase(Main.class.classLoader.getResource("webapp").toExternalForm());

        app.handler.addServlet("/*", DefaultServlet.class);
        app.handler.addServlet("/api/v1/*", JerseyServlet.class);
        app.handler.addServlet("/ws/*", WSServlet.class);

        app.run();
    }
}

3) Collect everything in a jar-nickname, write the main file in the manifest. In general, I collected all this with a gradle with the application plugin:
apply plugin:'application'
...
mainClassName = "your.package.app.Main"

PS the code was in Groovy, I rewrote it, but MB could mess up somewhere.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question