Web servlet url pattern - servlets

How would I express a url like:
<context>/{id}/email in the #WebServlet("...") syntax?
the default/context is users

Answering my own question. It does not appear like dynamic URL patterns are allowed in the #WebServlet("...").
I had to create a URL filter that would parse an incoming URL, extract {id} from it and set it as an attribute in the Session, and forward the request to the appropriate Servlet.

Related

What exactly is URL rewriting?

Which of them is correct definition of URL rewriting?
Shortening of URL for end-user as elaborated here
Appending extra arguments to URL sent to server for session management
I am confused over which one was invented first, and which one should be correct definition of URL re-write?
URL rewriting is simply what its name implies: rewriting/modification of URLs.
This can be used for shortening URLs, and it can be used for appending query parameters, but it’s not restricted to these two use cases.
To make the URL more readable
Example www.abc.com?id=1 rewrite it to www.abc.com/1

How to remove query string or how to maintain constant URL using URL rewrite

How to maintain constant URL?
For example:
http:// test23232 /temp/temp.aspx?a=1&b=1
a,b,query string parameter name get differ dynamically page to page(want to use those parameter but not dispaly for users)
While redirecting ,whatever the value present after ? should be removed and final URL displayed to users:
http:// test23232 /temp/temp.aspx or http:// test23232 /temp
Or any constant url post login mentioned throughout entire application.
I can acheive this by iframe, but how can I do by doing web.config through rule or global ascx.
or
whatever page redirect
http : //localhost /test/security / login.aspx
http : //localhost /test/security / main.aspx
http : //localhost /test/security / details.aspx
I want to show to browser as
http :// localhost / reap/ security /
Is it possible?
Use Session to store the values of a and b and keep the url simple.
You can send the necessary parameter using post method instead of get method.
More secure way of passing them is to store them into session variable.
that might make it more "secure" since then the client cannot change the variables by editing the source.
It will depends on how you really want to do.
The session parameters will keep on changing dynamically for every request.We can go for cookies.
Yet this link might be useful for url rewriting

Block URL's and Invalidate them

This is a valid url
URL1:
http://www.itsmywebsite.com/showproduct.aspx?id=127
http://www.itsmywebsite.com/browseproduct.aspx?catid=35
but this is not
URL2:
http://www.itsmywebsite.com/showproduct.aspx?id=-1%27
http://www.itsmywebsite.com/browseproduct.aspx?catid=-1%27
How can I block URL2 and the ones containing a string of format "-1%27" and invalidate the request. It's an automated bot sending this request so basically I want to just block the request in probably Global.asax? Please advise.
Well, those are both perfectly valid URLs. Your "URL2" is simply percent-encoded. Since 0x27 is an ASCII apostrophe, your percent-encoded URL2s are exactly the same as
http://www.itsmywebsite.com/showproduct.aspx?id=-1'
http://www.itsmywebsite.com/browseproduct.aspx?catid=-1'
Perhaps your web page should be validating the data it receives on the query string and throwing an error.
Which version of iis are you using? If 7.0 or later use the URL rewrite module to reject invalid urls such as those ending in =-1
See an example blocking domains ( regex patterns ) here: http://www.hanselman.com/blog/BlockingImageHotlinkingLeechingAndEvilSploggersWithIISUrlRewrite.aspx

Spring MVC URL Redirecting to login page

I have requirement is like below.
The user can call the url like domainname/applicationname/instancesname
For Ex: abc.com/xyz/pqr
From the URL with instance name I need to take and i need to redirect to the login page.
but what ever the user is enter the URL, I should keep in browser url.
[Because user may bookmark the URL]
Think I will receive the instance name dynamically.
how can i use this in Spring MVC.
The main concept is single url we are handling with multiple instances.
Unless you don not pass any url parameters with abc.com/xyz/pq this url it wont be a problem. Book mark url will work since you have the request mapping in your controller.

How to pull Domain portion of Url from incoming HttpRequest

I looked up the various request urls that you can grab from an HttpRequest. But I can't find how you can grab just the domain. Also would you call that portion of the string the domain or what? What's the formal term to call a string such as http://yourdomain.com? I want the http:// included without me having to prefix the yourdomain.com. I'm not sure what property I'm looking for.
Anyone know how grab that portion of the incoming HttpRequest? What do you call it?
http:// is the protocol; yourdomain.com is the host.
You can get either of them from the Request.Url property.
//your httprequest is called req you could do this.
Uri requesturi = req.Url;
string domain = requesturi.Host;

Resources