请求的资源不可用Glassfish 4

时间:2016-07-03 11:07:28

标签: java eclipse jsp glassfish

我最近开始研究Web应用程序,并试图建立一个练习项目来尝试不同的东西。但我陷入了一个非常初始的阶段,我搜索了很多但是找不到我的问题的解决方案。我已将项目与EAR项目相关联,并将耳朵部署在服务器上。

这是我遇到问题的项目设置:

的web.xml

   <?xml version="1.0" encoding="UTF-8"?>
   <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
        <display-name>College Administration</display-name>
        <servlet>
            <servlet-name>loginServlet</servlet-name>
            <servlet-class>kumar.suraj.college.administration.login.LoginServlet</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>loginServlet</servlet-name>
            <url-pattern>/login</url-pattern>
        </servlet-mapping>
   </web-app>

application.xml中

  <?xml version="1.0" encoding="UTF-8"?>
  <application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee"   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" id="Application_ID"   version="7">
  <display-name>web-college-administrationEar</display-name>
  <module>
       <web>
           <web-uri>web-college-administration.war</web-uri>
           <context-root>web-college-administration</context-root>
       </web>
  </module>
  </application>

的glassfish-web.xml中

 <?xml version="1.0" encoding="UTF-8"?>

 <!DOCTYPE glassfish-web-app PUBLIC "-//GlassFish.org//DTD GlassFish  Application Server 3.1 Servlet 3.0//EN" "http://glassfish.org/dtds/glassfish- web-app_3_0-1.dtd">
 <glassfish-web-app>
      <context-root>web-college-administration</context-root>
 </glassfish-web-app>

的login.jsp

    <!DOCTYPE html>
    <html>
    <head>
         <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
         <title>Login Page</title>
    </head>
    <body>
        <form name="login" action="login" method="post" accept-charset="utf-8">
             <label for="usermail  ">Email</label> 
             <input type="email" name="usermail" placeholder="yourname@email.com" required>
             <br/> 
             <label for="password  ">Password</label> 
             <input type="password" name="password" placeholder="password" required> 
             <br/>      
             <input type="submit" value="Login">
         </form>
    </body>
    </html>

LoginServlet.java

package kumar.suraj.college.administration.login;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class LoginServlet
*/
public class LoginServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public LoginServlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
@Override
protected void doGet(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    response.getWriter().append("Served at: ").append(request.getContextPath());
    response.getWriter().append("Hello Suraj");
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)
 */
@Override
protected void doPost(final HttpServletRequest request, final HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub
    this.doGet(request, response);
  }

}

login.jsp位于我项目的WebContent / WEB-INF文件夹中。

当我点击网址http://localhost:53809/web-college-administration/login

根据LoginServlet.java的doGet方法,我得到以下内容“服务于:/ web-college-administrationHello Suraj”。

但是当我点击网址http://localhost:53809/web-college-administration/login.jsp时,我收到以下错误:

   HTTP STATUS 404 - NOT FOUND
   type status report
   message Not Found
   description The requested resource is not available.

在eclipse控制台中,我收到以下消息:

   2016-07-03T16:34:18.969+0530|Severe: PWC6117: File "null" not found.

有人可以告诉我我的设置有什么问题吗?

1 个答案:

答案 0 :(得分:0)

  

login.jsp位于我项目的WebContent / WEB-INF文件夹中。

您能否将login.jsp放入项目的WebContent文件夹中,然后清理项目并再次尝试网址:http://localhost:53809/web-college-administration/login.jsp