problem with struts actions and redirections

Posted by Casey on Stack Overflow See other posts from Stack Overflow or by Casey
Published on 2010-05-12T21:38:03Z Indexed on 2010/05/12 22:14 UTC
Read the original article Hit count: 226

Filed under:
|

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"><web-app>
<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">

<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

© Stack Overflow or respective owner

Related posts about java

Related posts about struts2