tags:

views:

43

answers:

3

I am trying to update a simple web app that was built with struts2, jsp and standard servlets. I am trying to redirect a url to a specific action but can't seem to get it to work right. For example, the url that is correct is:

http://localhost:8080/theapp/lookup/search.action

Here is my web.xml:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
                     "http://java.sun.com/dtd/web-app_2_3.dtd"&gt;&lt;web-app&gt;
<display-name>theapp</display-name>

<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>

<listener>
    <listener-class>
        org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener> 

And here is my struts.xml:

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

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration    
2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"&gt;

<default-action-ref name="search" />

<action name="search" method="search" class="com.theapp.SearchAction" >
    <result>index.jsp</result>
    <result name="input" >index.jsp</result>
    <result name="error" type="redirect">site_locator_mobile/error.action</result>
</action>

The problem here is that if I don't specify the correct url as above, I just get the index.jsp file, but without any properties in index.jsp being processed because the information is contained in the servlet.

What I would like to is if someone just entered:

http://localhost:8080/theapp/lookup/ 

than they would be taken to:

http://localhost:8080/theapp/lookup/search.action

Thanks

A: 

Maybe you can specify a servlet as a welcome file:

<welcome-file-list>
<welcome-file>search.action<welcom-file>
<welcome-file-list> 

Note: some people report that a file called search.action must actually exist for this to work.

Another option is to have your index.jsp redirect to search.action and use another result jsp:

<% response.sendRedirect("search.action"); %>

Edit: It is also possible to add a filter-mapping directive directly to web.xml which redirects requests for /theapp/lookup/ to /theapp/lookup/search.action

Seems more complex, though.

caas
The welcome-file approach isn't going to work for me as it would redirect for the entire application. The index.jsp also has stuff in it that I need to use, it's not just a placeholder. I suppose I could rename the current file to something else and put an index.jsp that redirects to the appropriate action.
Casey
A: 

Edit: deleted this answer and put it above

caas
A: 

This may sound stupid, but can you post the entire contents of struts.xml file? Have you added a namespace to the struts xml file. You are trying to look up myApp/lookup/someAction.action. I think you should have a name space defined for your package.

Kartik