struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dirk Forchel <dirk.forc...@exedio.com>
Subject Re: [S2] ServletDispatcherResult (dispatcher) and forwarding to Actions
Date Tue, 16 Dec 2008 08:17:59 GMT

okay, I could strip off the context path from my "referer", but using a
relative URL like "/welcome.action" or "/demostore/welcome.action" doesn't
work either. Only something like "/jsp/pages/welcome.jsp" or similiar (a
relative URL with a JSP resource) works for me. But I wanna use Tiles, so
this result doesn't help me and I need a forward to a "Action" rather than a
JSP. If validation fails on my search action, the field error should be
displayed on the same page the input error occured. The seach form is used
on almost every page. 
This problem drives me almost insane!!! You can test it by your own.
Here is my Test-Configuration (without Tiles) and almost the complete code:

struts.xml:

<struts>
   <package name="demostore" extends="struts-default">
      <default-interceptor-ref name="paramsPrepareParamsStack"/>
        
      <default-action-ref name="welcome"/>
		
      <global-results>
	<result name="input">${referer}</result>			
      </global-results>
		
      <action name="search" class="com.foo.SearchAction">
	<result>/jsp/pages/search.result.jsp</result>
      </action>
   	
      <!-- Using Wildcard mapping for all actions without action classes -->
      <action name="*" class="com.foo.action.ForwardAction">
         <result>/jsp/pages/{1}.jsp</result>  			
      </action>
   </package>	
</struts>


BaseAction.java:

public class BaseAction extends ActionSupport implements
ServletRequestAware, Preparable
{
   private String referer;
   protected HttpServletRequest request;
	
   @Override
   public void setServletRequest(HttpServletRequest request)
   {
      this.request = request;
   }

   @Override
   public void prepare() throws Exception {
      referer = request.getHeader( "Referer" );
      if (referer==null)
         referer = request.getContextPath();
   }
	
   public String getReferer() {
      // THIS WORKS
      // return "/jsp/pages/welcome.jsp";
      // THIS DOES'NT WORK
      // return "/welcome.action";
      // THIS DOESN'T WORK EITHER
      return referer;
   }	
}

ForwardAction.java:

public class ForwardAction extends BaseAction 
{
   public String execute() throws Exception 
   {
      addToHistory(getServletRequest());
      return executeInternal();
   }

   protected void addToHistory(HttpServletRequest request)
   {
      // Request History
      // History.addEntry(request);
   }
	
   protected String executeInternal() throws Exception 
   {
      return SUCCESS;
   }
}

SearchAction.java:

public class SearchAction extends BaseAction
{
   private String searchString;
	
   public String execute() throws Exception 
   {	
      // DO SOME SEARCH
      return SUCCESS;
   }

   public void setSearchString(String searchString) {
      this.searchString = searchString;
   }

   public String getSearchString() {
      return searchString;
   }	
}

welcome.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" 
	import="com.exedio.demostore.web.Constants" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<html>
   <head>
      <meta http-equiv="Content-Type" content="text/html; charset=UTF8">
      <meta http-equiv="Content-Style-Type" content="text/css;
charset=UTF8">
      <title><s:text name="welcome.headline"/></title>		
      <link rel="stylesheet" type="text/css" href="css/default.css">	
</head>
   <body>
      <h1><s:text name="welcome.headline"/></h1>
      <s:include value="form.search.jsp" />
   </body>
</html>

form.search.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" 
	import="com.exedio.demostore.web.Constants" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<s:form action="search">
      <label for="searchString"><s:text name="search.term"/></label>
      <s:textfield name="searchString" />
      <s:submit key="search.submit" />
</s:form>

SearchAction-validation.xml:

<!DOCTYPE validators PUBLIC "-//OpenSymphony Group//XWork Validator
1.0.2//EN" "http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">

<validators>
    <field name="searchString">
        <field-validator type="requiredstring">
            <message key="error.searchstring.required"/>
        </field-validator>
    </field>
</validators>



Nils-Helge Garli wrote:
> 
>>
>> The getter-method for the referer property returns something like
>> "http://localhost:9001/welcome.action", cos the search-form is included
>> in
>> my welcome-page. I've got the feeling, that Tomcat's
>> ApplicationDispatcher
>> makes some request string modifications in accordance to the servlet
>> context
>> path.
>> The location after creating the dispatcher is
>> "//http:/localhost:9001/welcome.action". An obviously complete useless
>> URI.
>>
>>
> 
> According to the servlet specification, the path to the request
> dispatcher must be relative to the root of the servlet context,
> starting with the '/' character, so an absolute url won't work.
> 
> Nils-H
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/-S2--ServletDispatcherResult-%28dispatcher%29-and-forwarding-to-Actions-tp20950033p21028954.html
Sent from the Struts - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Mime
View raw message