开发者

Redirection of a url when clicking on menu

开发者 https://www.devze.com 2023-01-23 06:57 出处:网络
<li><a href=\"<%= UTIL.getServletPath(\"/SetupPage?PG=setupusersettings\") %>\"> <span>Settings</span></a>
<li><a href="<%= 
UTIL.getServletPath("/SetupPage?PG=setupusersettings") %>">
<span>Settings</span></a>

public String getServletPath(String fileName)
    {
        if(!fileName.startsWith("/"))
            fileName = "/" + fileName;
        return getContextPath() + fileName;
    }

public String getContextPath()
    {
        try
        {
            return request != null ? request.getContextPath() : "";
        }
        catch(Exception ex)
        {
            DBGlobals.Error(ex);
            return "";
        }
    }

public i开发者_如何学JAVAnterface HttpServletRequest extends javax.servlet.ServletRequest {

 java.lang.String getContextPath();

I have a few questions..

  1. What does getServletPath do?
  2. What does getContextPath do?
  3. Canyone explain me the flow?


original derived from Oracle's specs:

http://download.oracle.com/javaee/1.2.1/api/javax/servlet/http/HttpServletRequest.html

getServletPath

public java.lang.String getServletPath() Returns the part of this request's URL that calls the servlet. This includes either the servlet name or a path to the servlet, but does not include any extra path information or a query string. Same as the value of the CGI variable SCRIPT_NAME.

getContextPath

public java.lang.String getContextPath() Returns the portion of the request URI that indicates the context of the request. The context path always comes first in a request URI. The path starts with a "/" character but does not end with a "/" character. For servlets in the default (root) context, this method returns "". Returns: a String specifying the portion of the request URI that indicates the context of the request

I think that the spec is descriptive enough.

Regards.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号