Closed Thread Icon

Topic awaiting preservation: URL Rewriting with Java (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12420" title="Pages that link to Topic awaiting preservation: URL Rewriting with Java (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: URL Rewriting with Java <span class="small">(Page 1 of 1)</span>\

 
WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 09-12-2002 20:49

I have a piece of code here, what I am expecting it to do is perform a URL rewrite. What I plan on having is the servlet mapped to /* (being the root) so that the servlet would process all of the requests to the webserver. From there I would want it to perform URL rewritting along the lines of what is outlined below. (turn /departmentname/ filename.html into index.jsp?department=departmentname&page=filename).

The obvious solution you would prolly scream at me would to use mod_rewrite. However, we are running an IIS server (please don't ask me why, the reasoning behind using an IIS just make sence to the IT people). The next solution would be to use an ISAPI Filter. However, I would rather have it done with Java if possible, since it would save me from having to write up a proposal.

code:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class URLHandler extends HttpServlet
{
public void service(HttpServletRequest req, HttpServletResponse res )
throws ServletException, IOException
{
res.setContentType("text/html");

String url = req.getRequestURL();
String department = getDepartment(url);
String page = getPage(url,department);
String page_to_request = "/index.jsp?department=" + department + "&page=" + page;

res.encodeURL(url);
res.sendRedirect(page_to_request);
}

/**
* This function takes in a URL mapped to the webserver root which would be /
* All URL's will follow [url=http://www.stonybrook.edu/stuaff/*]http://www.stonybrook.edu/stuaff/*[/url]
* Therefore we are expecting a URL of this format
**/
private static String getDepartment(String url)
{
String department = "stuaff";

url = url.substring(url.indexOf("/stuaff/") + 8);

if (url.indexOf("/") == -1) return department;
else return url.substring(0,url.indexOf("/"));
}

/**
* This function takes the department name returned from
* getDepartment and uses it to get the page name.
**/
private static String getPage(String url, String department)
{
String page = null;

url = url.substring(url.indexOf(department + "/")+department.length() + 1);
page = url.substring(0,url.indexOf("."));
return page;
}
}



InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-13-2002 10:29

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 09-13-2002 15:07

Hmmm... that is incredibly interesting.

When I contacted QwerkSoft they told me that it could be done with a Mapped servlet. But I am not sure exactly how to implement it. It would have been so much easier if they just let up use an Apache Server. WTF do IT departments have to be so tied into the MS solution. It is a damn shame that they chose to spend $1200US on server software that does not contain the functionality or performance of a free piece of software.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 09-13-2002 15:38

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

WarMage
Maniac (V) Mad Scientist

From: Rochester, New York, USA
Insane since: May 2000

posted posted 09-13-2002 20:14

Yeah, I have contacted some PHD's on this topic. I am am pretty sure that Java should have the capabilities to achomplish this type of task it is just a matter of figuring out how, or writing up a proposal to porcure and ISAPI filter.

« BackwardsOnwards »

Show Forum Drop Down Menu