JSP的目录结构?

时间:2015-05-19 19:25:01

标签: java jsp servlets

通过一些问题并阅读本文

  

我是否需要遵循目录结构来运行简单的JSP?

JSP的目录结构究竟是什么?

并回答

private string SendHttpRequest(string url, out int statusCode, string method = "GET", object postData = null, string contentType = "application/json")
{
    bool isPost = method.Equals("POST", StringComparison.CurrentCultureIgnoreCase);

    byte[] content = new ASCIIEncoding().GetBytes(isPost ? JsonConvert.SerializeObject(postData) : "");

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

    request.AllowAutoRedirect = true;
    request.Method = method;
    request.ContentType = contentType;
    request.ContentLength = postData == null ? 0 : content.Length;

    if (isPost && postData != null)
    {
        Stream reqStream = request.GetRequestStream();
        reqStream.Write(content, 0, content.Length);
    }

    HttpWebResponse response = null;

    //Get the response via request.GetResponse, but if that fails,
    //retrieve the response from the exception
    try
    {
        response = (HttpWebResponse)request.GetResponse();
    }
    catch (WebException ex)
    {
        response = (HttpWebResponse)ex.Response;
    }

    string result;

    using (StreamReader sr = new StreamReader(response.GetResponseStream()))
    {
        result = sr.ReadToEnd();
    }
    statusCode = (int)response.StatusCode;

    response.Close();

    return result;
}

1 个答案:

答案 0 :(得分:0)

  

JSP的目录结构究竟是什么?

就像我们维护java类的包结构一样,我们可以为jsp页维护一个目录或文件夹结构,以便更好地组织。此外,如果您想直接从浏览器访问jsps,请将它们保存在WEB-INF文件夹之外。

enter image description here

  

我是否需要遵循目录结构来运行简单的JSP?

不,它不是必须遵循目录结构。您可以将所有jsps转储到一个文件夹中。跑他们。