user3615309
user3615309

Reputation: 1

Populating drop down on the index page in Struts 2.x

1.  I'm making a web application in which i need to interact with the database and get a list of values and populate them in a drop down (which is a form element in the index.jsp). My form has a drop down which i intend to populate with area codes, which are in turn present in a database table. I was wondering if i can fire an action as the intial hit? i.e. Can i fire an action as a part of the welcome-list in the web.xml ?

2.  Also , i face an issue in which when i deploy the application on a Websphere application server and access the link as servername/projectname - it gives an error stating

Messages: •There is no Action mapped for namespace / and action name .
 

so i'm forced to access the application as servername/projectname/index.jsp - which runs fine ! I fail to understand the problem as it doesn't show up on my local machine and only when i deploy it on the server. Please find below my 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_2_5.xsd" id="WebApp_ID" version="2.5">
      <display-name>FirstRtWebGUIRevive</display-name>
      <welcome-file-list>
        <welcome-file>/home.jsp</welcome-file>
      </welcome-file-list>
      <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
      </filter>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    </web-app>

and with that my struts.xml :

    <?xml version="1.0" encoding="UTF-8"?>

    <struts>
        <constant name="struts.devMode" value="true" />
        <package name="default" extends="struts-default" namespace="/">
            <action name="hit" class="com.action.MakeTransaction" method="concurrentPull">
                <result name="success">/resultMain.jsp</result>
                <result name="empty">/homeRedirect.jsp</result>
                <result name="noState">/homeRedirectNoState.jsp</result>
            </action>
            </package>
    </struts>

Note that i did add the namepace="/" in my package declaration. Kindly help :D Thanks in advance

Upvotes: 0

Views: 392

Answers (1)

mohamed sulibi
mohamed sulibi

Reputation: 526

Try calling using servername/projectname/hit

you can call using servername/projectname if you add default-action-ref tag in struts configuration,

<struts>
...
<package>
...
<default-action-ref name="hit"/> 
... 
</package>
</struts>

but keep in mind that this line will forward all requests belong to / namespace that not exist a mapping for them, for examples:

servername/projectname will handle by => servername/projectname/hit servername/projectname/AnyValidName will handle by => servername/projectname/hit servername/projectname/Mohamed_Sulibi will handle by => servername/projectname/hit

Upvotes: 0

Related Questions