Bonjour !

Je me met à Java EE ! Je me base donc sur un tutoriel Java. Sauf que ce tuto se fait avec eclipse et tomcat6, alors que je développe avec netbeans et glassfish.

Donc dans ce tuto, on nous apprends qu'il faut mapper notre servlet dans le fichier web.xml sauf qu'il n'y en a pas dans le projet que j'ai crée.
Il y a sun-web.xml à la place, du coup j'édite le sun-web.xml à la place du web.xml

ça marchait jusqu'à ce que je veuille mettre du java dans mes fichiers .jsp

J'obtiens ce type d'erreur :
SEVERE: DPL8007: Invalid Deployment Descriptors element servlet-class value Loggin.Loggin
SEVERE: DPL8007: Invalid Deployment Descriptors element servlet-name value logginServlet
SEVERE: DPL8007: Invalid Deployment Descriptors element url-pattern value /logged.do.jsp
INFO: Loading application WebApplication1 at /WebApplication1
INFO: WebApplication1 was successfully deployed in 428 milliseconds.
WARNING: StandardWrapperValve[jsp]: PWC1406: Servlet.service() for servlet jsp threw exception
java.lang.NullPointerException
Je google l'erreur pour voir de quoi ça parle et je tombe sur cette conversation où quelqu'un a exactement la même erreur que moi et qui a aussi modifié le fichier sun-web.xml (pas à des même fins par contre). Et on lui repond ça :
I don't see <context-param> in the sun-web.xml DTD. So I guess you are not supposed to do this there. Place this in the regular web.xml, it will work there.
Donc là je sais pas trop quoi faire...

sun-web.xml
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-web-app PUBLIC "-//Sun Microsystems, Inc.//DTD GlassFish Application Server 3.0 Servlet 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-web-app_3_0-0.dtd">
<sun-web-app error-url="">
  <context-root>/WebApplication1</context-root>
  <servlet>
    <servlet-name>logginServlet</servlet-name>
    <servlet-class>Loggin.Loggin</servlet-class>
  </servlet>
  <servlet-mapping>
      <servlet-name>logginServlet</servlet-name>
      <url-pattern>/logged.do.jsp</url-pattern>
  </servlet-mapping>
  <class-loader delegate="true"/>
  <jsp-config>
    <property name="keepgenerated" value="true">
      <description>Keep a copy of the generated servlet class' java code.</description>
    </property>
  </jsp-config>
</sun-web-app>
2ème jsp où j'essaye de mettre du java (si j'enlève le if, ça marche...)
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
<%-- 
    Document   : logged.jsp
    Created on : 28-Feb-2012, 12:39:43
    Author     : s155651
--%>
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        blaaaa
        <%
            Object log = request.getAttribute("logginSuccessful");
            java.lang.Boolean log2 = (java.lang.Boolean) log;
            if (log2) {
 
                System.out.println("laaaaa");
            }
        %>
    </body>
</html>
mon servlet
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Loggin;
 
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
 
/**
 *
 * @author s155651
 */
public class Loggin extends HttpServlet {
 
    private String password;
    private String username;
 
    public Loggin() {
        password = null;
        username = null;
    }
 
    @Override
    public void doGet(HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {
        Boolean display = Math.random()>0.5;
        request.setAttribute("logginSuccessful", display);
        request.getRequestDispatcher("logged.jsp").forward(request, response);
    }
 
    @Override
    public void doPost(HttpServletRequest request,
            HttpServletResponse response)
            throws IOException, ServletException {
 
        doGet(request, response);
    }
 
    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }
 
    /**
     * @param password the password to set
     */
    public void setPassword(String password) {
        this.password = password;
    }
 
    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }
 
    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }
 
    public boolean isValid() {
        return LogginBD.loggin(username, password);
    }
}
1er jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<%-- 
    Document   : index
    Created on : 27-Feb-2012, 11:27:22
    Author     : Sabine
--%>
 
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
 
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
    </head>
    <body>
        <h1>Entry Form</h1>
        <form name="Login" action="logged.do.jsp" method="post">
            User name:
            <input type="text" name="username"/>
            Password :
            <input type="password" name="password"/>
            <input type="submit" name="logginOK" value="OK" />
        </form>
    </body>
</html>
PS contexte : J'essaye de faire un loggin + mot de passe avec une bd derrière