tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From William Maurer <>
Subject URL rewriting ignored for "/whatever" context path; broken for "/" context path
Date Tue, 03 Apr 2001 04:21:52 GMT
	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.


	My servlet executes the following 3
	lines of code as the last step in processing each request in

	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. 

	The following happens in for

	toAbsolute(/ShoppingStep.jsp) returns

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

	Stopped at line 366 in
	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/ + 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)
	results in a "The document contains no data" message being
	displayed by the browser. It appears the jsessionid is the
	problem per 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

View raw message