0

This is the war file contents:

tar -xvf search.war
x META-INF/
x META-INF/MANIFEST.MF
x WEB-INF/
x WEB-INF/classes/
x WEB-INF/classes/com/
x WEB-INF/classes/com/init/
x WEB-INF/classes/com/init/HelloServlet.class
x WEB-INF/web.xml

web.xml contents:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
          http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5">
    <servlet>
        <servlet-name>homeServlet</servlet-name>
        <servlet-class>com.init.HelloServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>homeServlet</servlet-name>
        <url-pattern>/search*</url-pattern>
    </servlet-mapping>
</web-app>

HelloServlet.java content

package com.init;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @author sudeep
 * @since 31/08/16
 */
public class HelloServlet extends HttpServlet {

    @Override
    public void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        PrintWriter printWriter = null;
        try {
            printWriter = httpServletResponse.getWriter();
        } catch (IOException e) {
            e.printStackTrace();
        }
        httpServletResponse.setContentType("text/html");
        printWriter.print("<html><body><p>Hello World!</p></html></body>");
        printWriter.close();
    }
}

Then deploying war on glassfish with this command:

asadmin --port 5000 --host localhost deploy search.war

when i look to start the application search using glassfish ui, I get these:

enter image description here

enter image description here

What is wrong here?

sudeepdino008
  • 3,194
  • 5
  • 39
  • 73

1 Answers1

0

From the admin it looks like the webapp context name is search (which makes sense, by default it is the same name as the war). That makes the url for your webapp http://hostname:8080/search .

Your servlet is then mapped to url pattern /search*, which is in fact relative to the url of your webapp. So it triggers on urls that start with http://hostname:8080/search/search . If you try this url pattern the servlet should be invoked.

What you probably want to achieve is that your webapp deploys as the root web application so the context name won't be part of the url. Since you're using Glassfish and use asadmin you can do this:

asadmin --port 5000 --host localhost deploy --contextroot "/" search.war
Gimby
  • 5,095
  • 2
  • 35
  • 47