Reddy_73
Reddy_73

Reputation: 134

Server returned http response code 407 for url: "http://struts.apache.org/dtds/struts-2.1.7.dtd

I am new to Struts2. I was trying to execute a simple Struts2 program. Apparently my struts.xml is not invoking the action.

It shows a warning Server returned http response code 407 for url: "http://struts.apache.org/dtds/struts-2.1.7.dtd in my struts.xml.

struts.xml:

<?xml version="1.0" encoding="UTF-8"?>
  <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
    "http://struts.apache.org/dtds/struts-2.1.7.dtd">

 <struts>
   <package name="default" extends="struts-default">
      <action name="hello" class="com.FirstStruts.ExampleStruts" method="execute">
            <result name="success">/Helloworld.jsp</result>
      </action>
   </package>

 </struts>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="http://java.sun.com/xml/ns/javaee" 
   xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
   id="WebApp_ID" version="3.0">

   <display-name>Struts 2</display-name>
   <welcome-file-list>
      <welcome-file>index.jsp</welcome-file>
   </welcome-file-list>
   <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
         org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
   </filter>

   <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
   </filter-mapping>
</web-app>

Action:

package com.FirstStruts;

public class ExampleStruts {
    private String f_name;
    private String l_name;

    public String execute() throws Exception {
        System.out.println("Hello. in execeute");
        return "success";   
    }

    public String getF_name() {
        return f_name;
    }

    public void setF_name(String f_name) {
        this.f_name = f_name;
    }

    public String getL_name() {
        return l_name;
    }

    public void setL_name(String l_name) {
        this.l_name = l_name;
    }


}

When I try to execute, I am getting the error There is no Action mapped for namespace / and action name ExampleStruts.

I am using the jars mentioned in http://www.nabisoft.com/tutorials/struts2/basic-struts2-project-setup

Could you please help me with it?

Upvotes: 1

Views: 1085

Answers (1)

Armaggedon
Armaggedon

Reputation: 419

Your action is called hello, no ExampleStruts, so it won't find it. Change your struts.xml file:

<action name="ExampleStruts" class="com.FirstStruts.ExampleStruts">
    <result>/Helloworld.jsp</result>
</action>

or invoke the action correctly in your index.jsp.

Also, you need to extend your action from ActionSupport, so it will be recognized as an action.

Upvotes: 1

Related Questions