RE: REPOST: Please HELP!: URL Mapping Problems in servlet
try req.getPathInfo() in place of getServletPath() you can use getRequestURL() which will provide the requested URL that you are trying to rebuild. Charlie -Original Message- From: Mark B. Indictor [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 12:24 PM To: 'Tomcat Users List' Subject: REPOST: Please HELP!: URL Mapping Problems in servlet OK -- I'm having a related problem: I can hit my servlet with the following httpd.conf and web.xml file setup with these two URLs: http://hostname:8080/s2/sb/ And http://hostname/SiteBlocks/sb/ From within the servlet, I am trying to reconstruct the URL. I am using the following code: ... private String buildURL( HttpServletRequest req ) { // Build a new absolute URL StringBuffer url = new StringBuffer(); url.append( req.getScheme() ); // http url.append( :// );// http:// url.append( req.getServerName() ); // http://hostname url.append( : ); // http://hostname: url.append( req.getServerPort() ); // http://hostname:80 url.append( req.getServletPath() ); // http://hostname:80/SiteBlocks/sb return url.toString(); } ... Unfortunately, the URL this produces is either: http://hostname:8080/sb or http://hostname/sb, and not http://hostname:8080/s2/sb or http://hostname/SiteBlocks/sb as expected. Am I doing something wrong? If so, how can I get the desired result? Thanks for any assistance! Here's an excerpt from my httpd.conf file: ... IfModule od_webapp.c WebAppConnection warpconnection warp localhost:8008 WebAppDeploy examples warpConnection /examples/ WebAppDeploy SiteBlocks warpConnection /SiteBlocks/ /IfModule ... Here's my entire web.xml file: ?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 servlet servlet-name SiteBlocks /servlet-name servlet-class S2Server /servlet-class init-param param-nameresource/param-name param-value/usr/local/jakarta-tomcat-4.0.2/webapps/SiteBlock s/WEB-INF/Site BlocksServer.properties/param-value /init-param /servlet servlet-mapping servlet-name SiteBlocks /servlet-name url-pattern /sb /url-pattern /servlet-mapping /web-app - Mark == Mark Indictor -- V.P. Engineering [EMAIL PROTECTED] http://www.site2.com Phone:(310)451-3472 FAX:(240)220-6341 http://keyserver.pgp.com/pks/lookup?op=getsearch=0x8959F966 == -Original Message- From: Dave Ferguson [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 26, 2002 12:11 PM To: Tomcat Users List Subject: Re: servlet-mapping problem This is basic stuff. It should work. What URL are you using to invoke the servlet? With no mapping the URL would be http://server/servlet/warservlet. If your mapping is url-pattern/blah/url-pattern then the URL would be http://server/blah. Restart Tomcat to be sure your changes take effect. - df -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: REPOST: Please HELP!: URL Mapping Problems in servlet
If the URL is: http://hostname/context/servlet/xxx Then: req.getPathInfo() returns: /xxx req.getRequestURI() returns:/context/servlet/xxx req.getServletPath() returns: /servlet How do I get just: /context/servlet OR How do I get Apache or Tomcat to respond to: http://hostname/servlet/xxx? Thanks - mbi == Mark Indictor -- Site2 Corporation [EMAIL PROTECTED] http://www.site2.com Phone:(310)451-3472 FAX:(240)220-6341 http://keyserver.pgp.com/pks/lookup?op=getsearch=0x8959F966 == -Original Message- From: Cox, Charlie [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 9:46 AM To: 'Tomcat Users List' Subject: RE: REPOST: Please HELP!: URL Mapping Problems in servlet try req.getPathInfo() in place of getServletPath() you can use getRequestURL() which will provide the requested URL that you are trying to rebuild. Charlie -Original Message- From: Mark B. Indictor [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 12:24 PM To: 'Tomcat Users List' Subject: REPOST: Please HELP!: URL Mapping Problems in servlet OK -- I'm having a related problem: I can hit my servlet with the following httpd.conf and web.xml file setup with these two URLs: http://hostname:8080/s2/sb/ And http://hostname/SiteBlocks/sb/ From within the servlet, I am trying to reconstruct the URL. I am using the following code: ... private String buildURL( HttpServletRequest req ) { // Build a new absolute URL StringBuffer url = new StringBuffer(); url.append( req.getScheme() ); // http url.append( :// );// http:// url.append( req.getServerName() ); // http://hostname url.append( : ); // http://hostname: url.append( req.getServerPort() ); // http://hostname:80 url.append( req.getServletPath() ); // http://hostname:80/SiteBlocks/sb return url.toString(); } ... Unfortunately, the URL this produces is either: http://hostname:8080/sb or http://hostname/sb, and not http://hostname:8080/s2/sb or http://hostname/SiteBlocks/sb as expected. Am I doing something wrong? If so, how can I get the desired result? Thanks for any assistance! Here's an excerpt from my httpd.conf file: ... IfModule od_webapp.c WebAppConnection warpconnection warp localhost:8008 WebAppDeploy examples warpConnection /examples/ WebAppDeploy SiteBlocks warpConnection /SiteBlocks/ /IfModule ... Here's my entire web.xml file: ?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 servlet servlet-name SiteBlocks /servlet-name servlet-class S2Server /servlet-class init-param param-nameresource/param-name param-value/usr/local/jakarta-tomcat-4.0.2/webapps/SiteBlock s/WEB-INF/Site BlocksServer.properties/param-value /init-param /servlet servlet-mapping servlet-name SiteBlocks /servlet-name url-pattern /sb /url-pattern /servlet-mapping /web-app - Mark == Mark Indictor -- V.P. Engineering [EMAIL PROTECTED] http://www.site2.com Phone:(310)451-3472 FAX:(240)220-6341 http://keyserver.pgp.com/pks/lookup?op=getsearch=0x8959F966 == -Original Message- From: Dave Ferguson [mailto:[EMAIL PROTECTED]] Sent: Tuesday, February 26, 2002 12:11 PM To: Tomcat Users List Subject: Re: servlet-mapping problem This is basic stuff. It should work. What URL are you using to invoke the servlet? With no mapping the URL would be http://server/servlet/warservlet. If your mapping is url-pattern/blah/url-pattern then the URL would be http://server/blah. Restart Tomcat to be sure your changes take effect. - df -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: REPOST: Please HELP!: URL Mapping Problems in servlet
-Original Message- From: Mark B. Indictor [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 1:17 PM To: 'Tomcat Users List' Subject: RE: REPOST: Please HELP!: URL Mapping Problems in servlet If the URL is: http://hostname/context/servlet/xxx Then: req.getPathInfo() returns:/xxx req.getRequestURI() returns: /context/servlet/xxx req.getServletPath() returns: /servlet How do I get just: /context/servlet I don't think there is a function to get the full request path without the final page/servlet name. This should get what you need: req.getRequestURI().substring(0,req.getRequestURI().lastIndexOf(/)) OR How do I get Apache or Tomcat to respond to: http://hostname/servlet/xxx? tomcat will already take a servlet named 'xxx' in this format unless you disabled the default servlet invoker in conf\web.xml. You will have to map /servlet/* to tomcat from apache. Charlie Thanks - mbi == Mark Indictor -- Site2 Corporation [EMAIL PROTECTED] http://www.site2.com Phone:(310)451-3472 FAX:(240)220-6341 http://keyserver.pgp.com/pks/lookup?op=getsearch=0x8959F966 == -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: REPOST: Please HELP!: URL Mapping Problems in servlet
I appreciate the help, but this still does not solve my problem. You see, I need to handle URLs of the following forms: http://hostname/context/servlet/xxx as well as: http://hostname/context/servlet With your suggestion, I would be truncating these to: http://hostname/context/servlet and http://hostname/context Respectively. The first behavior is desirable, the second is not! What I do not understand is why Apache and Tomcat conspire hide the 'context' element of the URL. I either need to find a way to isolate and retrieve the full path to the servlet (/context/servlet) or I need to find a way to set up Apache and Tomcat to recognize a URL that does not contain a context component (/servlet). Why does getServletPath() not return the whole path to the servlet, including its context, if this information is, in fact, required to access the servlet with a URL!? Any suggestions? Thanks! - mbi == Mark Indictor -- Site2 Corporation [EMAIL PROTECTED] http://www.site2.com Phone:(310)451-3472 FAX:(240)220-6341 http://keyserver.pgp.com/pks/lookup?op=getsearch=0x8959F966 == -Original Message- From: Cox, Charlie [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 10:44 AM To: 'Tomcat Users List' Subject: RE: REPOST: Please HELP!: URL Mapping Problems in servlet I don't think there is a function to get the full request path without the final page/servlet name. This should get what you need: req.getRequestURI().substring(0,req.getRequestURI().lastIndexOf(/))
RE: REPOST: Please HELP!: URL Mapping Problems in servlet
I think that this approach is very close to what you want. Instead of lastIndexOf(/) you could do lastIndexOf (or indexOf) getServletName. Another alternative would be to use lastIndexOf(getPathInfo()) on the request URI. As to why the methods return what they do, its because the spec says so. Randy -Original Message- From: Mark B. Indictor [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 2:03 PM To: 'Tomcat Users List' Subject: RE: REPOST: Please HELP!: URL Mapping Problems in servlet I appreciate the help, but this still does not solve my problem. You see, I need to handle URLs of the following forms: http://hostname/context/servlet/xxx as well as: http://hostname/context/servlet With your suggestion, I would be truncating these to: http://hostname/context/servlet and http://hostname/context Respectively. The first behavior is desirable, the second is not! What I do not understand is why Apache and Tomcat conspire hide the 'context' element of the URL. I either need to find a way to isolate and retrieve the full path to the servlet (/context/servlet) or I need to find a way to set up Apache and Tomcat to recognize a URL that does not contain a context component (/servlet). Why does getServletPath() not return the whole path to the servlet, including its context, if this information is, in fact, required to access the servlet with a URL!? Any suggestions? Thanks! - mbi == Mark Indictor -- Site2 Corporation [EMAIL PROTECTED] http://www.site2.com Phone:(310)451-3472 FAX:(240)220-6341 http://keyserver.pgp.com/pks/lookup?op=getsearch=0x8959F966 == -Original Message- From: Cox, Charlie [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 10:44 AM To: 'Tomcat Users List' Subject: RE: REPOST: Please HELP!: URL Mapping Problems in servlet I don't think there is a function to get the full request path without the final page/servlet name. This should get what you need: req.getRequestURI().substring(0,req.getRequestURI().lastIndexOf(/)) -- To unsubscribe: mailto:[EMAIL PROTECTED] For additional commands: mailto:[EMAIL PROTECTED] Troubles with the list: mailto:[EMAIL PROTECTED]
RE: REPOST: Please HELP!: URL Mapping Problems in servlet
Thanks, Randy. I think this will work. I thought of doing this, but thought that there must be an existing method for extracting this information. This solution, though workable, seems like a kludge. Is Apache's concept of 'contexts' spec'd? If so, doesn't it seem logical that there should be a way of determining what the 'context' is separate from the 'servlet', and visa versa, without resorting to custom string parsing? Anyway, back to work. Again, thank you for your help. - mbi == Mark Indictor -- Site2 Corporation [EMAIL PROTECTED] http://www.site2.com Phone:(310)451-3472 FAX:(240)220-6341 http://keyserver.pgp.com/pks/lookup?op=getsearch=0x8959F966 == -Original Message- From: Randy Layman [mailto:[EMAIL PROTECTED]] Sent: Wednesday, February 27, 2002 10:33 AM To: 'Tomcat Users List' Subject: RE: REPOST: Please HELP!: URL Mapping Problems in servlet I think that this approach is very close to what you want. Instead of lastIndexOf(/) you could do lastIndexOf (or indexOf) getServletName. Another alternative would be to use lastIndexOf(getPathInfo()) on the request URI. As to why the methods return what they do, its because the spec says so. Randy