2016-07-03 54 views
1

最近、Webアプリケーションの作業を開始し、さまざまなことを試してみるための練習プロジェクトを設定しようとしていました。しかし、私は非常に初期段階で立ち往生しており、私はたくさんのグーグルで探せましたが、私の問題に対する解決策を見つけることができませんでした。プロジェクトにEARプロジェクトを関連づけ、耳をサーバーに配置しました。リクエストされたリソースは利用できません。Glassfish 4

これは、私が問題に直面していたプロジェクトのセットアップです:

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="[email protected]" 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フォルダに配置されます。私は、URL http://localhost:53809/web-college-administration/login

を打つ

I取得「で提供してい:/ウェブ・カレッジ・administrationHelloスラジュ」アウトプット次LoginServlet.javaのdoGetメソッドごととして。

しかし、私は、URL、私は次のエラーを取得する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. 

私のセットアップ?

+0

プロジェクトのディレクトリ構造を投稿してください。 –

+0

ステータスコード404は利用できないリソース用です。 –

+0

こんにちは@RomanC私の答えに間違った情報が表示されますか? –

答えて

0

login.jspは、私のプロジェクトのWebContent/WEB-INFフォルダに置かれます。

あなたは、プロジェクトをきれいにしてみてくださいURL日食でプロジェクトのWebContentフォルダにlogin.jspを入れてもらえ:もう一度http://localhost:53809/web-college-administration/login.jspを?

+0

@SanjeevSahaはい、うまくいきました。あなたが言ったことを試していたので、返事に時間がかかりました。ご支援ありがとうございました。また、便利な場合は、あなたが良いリンクやチュートリアルを知っている場合は、私はいくつかのケースで見たようにどこのリソースを配置する必要があります戦争/耳とmavenとnonmaven –

+0

両方のWebプロジェクトのディレクトリ構造jspファイルはweb-infフォルダに置かれます。また、あなたのアプリケーションにプライベートなリソースを公開することができないように、web-infフォルダに保存することをお勧めします。 –

+0

@SurajKumarあなたは多くの良いチュートリアルをhttp://www.mkyong.com/で見つけることができます。 –

関連する問題