tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Maurer <mau...@dsplabs.com>
Subject URL rewriting ignored for "/whatever" context path; broken for "/" context path
Date Tue, 03 Apr 2001 04:21:52 GMT
Hi,
	I'm using Tomcat 3.2.1, and after searching the archives it appears URL
	rewriting is working OK. I must be doing something to mess
	things up. Thanks in advance for your help.

Bill

	My com.xxx.MyServlet servlet executes the following 3
	lines of code as the last step in processing each request in
	"doPost":

	1. String encodedNextURL = httpServletResponse.encodeURL(this.nextURL);
	2. RequestDispatcher rd = this.getServletContext().getRequestDispatcher(encodedNextURL);
	3. rd.forward(httpServletRequest, httpServletResponse);

	When my servlet's context path is "/whatever", then
	encodedNextURL is always the same as this.nextURL after line 1
	is executed. 
	
	Why?

	The following happens in HttpServletResponseFacade.java for
	this.nextURL=/ShoppingStep.jsp 

	toAbsolute(/ShoppingStep.jsp) returns
	http://localhost:8080/ShoppingStep.jsp 

	isEncodeable(http://localhost:8080/ShoppingStep.jsp) always
	returns false at lines 363-368 because
	!file.startsWith(contextPath) is true.

	Stopped at line 366 in HttpServletResponseFacade.java
	Thread-103[1] locals
	Method arguments:
	this = org.apache.tomcat.facade.HttpServletResponseFacade@80e6674
	location = http://localhost:8080/ShoppingStep.jsp
	Local variables:
	request = R( /whatever + /servlet/com.xxx.MyServlet + null)
	url = http://localhost:8080/ShoppingStep.jsp
	urlPort = 8080
	contextPath = /whatever
	file = /ShoppingStep.jsp

	String contextPath = request.getContext().getPath();
	if ((contextPath != null) && (contextPath.length() > 0)) {
	    String file = url.getFile();
	    if ((file == null) || !file.startsWith(contextPath))
		return (false);
	}

	encodedNextURL gets assigned /ShoppingStep.jsp
  
	When my servlet's context path is "/", then
	this.nextURL get's rewritten and
	encodedNextURL gets assigned
	/ShoppingStep.jsp;jsessionid=2nrrjkjci1 but 

	
	Forwarding the URL (see line 3 above)
	"/ShoppingStep.jsp;jsessionid=2nrrjkjci1" 
	results in a "The document contains no data" message being
	displayed by the browser. It appears the jsessionid is the
	problem per StaticInterceptor.java lines 199-212, because
	file is not a file or a directory as a result of jessionid
	hanging off the end of the path.  

Thread-102[1] locals
Method arguments:
  this = org.apache.tomcat.request.StaticInterceptor@80f0ddb
  req = R(  + /ShoppingStep.jsp;jsessionid=lo3hbfjvp1 + null)
Local variables:
  pathInfo = /ShoppingStep.jsp;jsessionid=lo3hbfjvp1
  ctx = Ctx(  )
  absPath = /home/maurer/ejpos/unix/local/jakarta-tomcat/webapps/ROOT/ShoppingStep.jsp;jsessionid=lo3hbfjvp1
  requestURI = /ShoppingStep.jsp;jsessionid=lo3hbfjvp1
  file = /home/maurer/ejpos/unix/local/jakarta-tomcat/webapps/ROOT/ShoppingStep.jsp;jsessionid=lo3hbfjvp1
  welcomeFile is not in scope
  redirectURI is not in scope



	File file=new File( absPath );

	if( file.isFile() ) {
	    if( debug > 0 ) log( "Setting handler to file " + absPath);
	    req.setNote( realFileNote, absPath );
	    req.setWrapper(  ctx.getServletByName( "tomcat.fileHandler"));
	    return 0;
	}

	if( ! file.isDirectory() ) {
	    // we support only files and dirs
	    if( debug > 0) log( "No file and no directory");
	    return 0; // no handler is set - will end up as 404
	}

Mime
View raw message