How to remove the project name from the Java Servlet URL

Asked

Viewed 255 times

1

I have a question and I’ve searched all over the internet and I haven’t found it, how the hell do I get the name of the project from the url in java? ex:

http://localhost:8084/MeuProjeto/login

for

http://localhost:8084/login

thank you!

Obs: jdk8

1 answer

1


Oops, I don’t know if you’re using a framework like Spring, but if you’re using pure Servlet you need to configure the project’s web.xml file:

Something like that:

<servlet>
    <servlet-name>LoginServlet</servlet-name>
    <servlet-class>pacote.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
    // Classe servlet que responde por essa URL
    <servlet-name>LoginServlet</servlet-name> 
    // URL que deseja mapear
    <url-pattern>/login</url-pattern> 
</servlet-mapping>

To create the file in Netbeans:

1. In the top menu click on File, choose New File.
2. On the screen that opens, select Web category, then select Standard Deployment Descriptor.
3. Click on Next.
4. Click Finish. The web.xml file will be created in the web/WEB-INF directory/.

  • Good evening, friend, and yes, I’m using pure Herbet. There is only one though, when I created the project I did not select to generate web.xml, and I am very lay in java, there is still how to generate it or need to copy from somewhere?

  • Everton Neri, Whereas you are using the Eclipse IDE: Right-click the project -> Java EE Tools -> Generate Deployment Descriptor Stub. Then it will be generated: /[NOME_PROJETO]/Webcontent/WEB-INF/web.xml

  • @pss1 support I’m actually using Netbeans, and for it I didn’t find the solution

  • @Everton Neri Includes in the above answer how to find this configuration within the Netbeans IDE. Hug.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.