Wenn ich versuche, um nutzen aus der Java-Klasse, die JSP, meine JSP-zeigt "nul"

Bin ich, bis ein Schüler in Java, bitte helfen Sie mir. Hier ist mein Beispiel code, wenn ich dieses Programm ausführen. Abzurufen sind die Informationen aus der Datenbank und speichert die Werte in der Java-Klasse ist und es durch senden des Wertes zu JSP aber wenn ich sehe JSP es zeigt den Wert "null"

Hier sind die 5 Dateien, die im Zusammenhang zu meinem problem keine Antworten oder Lösungen werden gerne angenommen.

-------------------------dies ist mein basic input form---------------------------

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WELCOME TO DISCOUNTLOVERS.IN</title>



<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div id="wrapper">
<div><%@include file="header.jsp" %></div>

<div><table width="920" border="0" cellpadding="0" cellspacing="0" id="main-content" > 

<form method ="post" action ="Registrationform" >
<tbody>
<tr>
<td width="382" valign="top" class="formtext">
<div>First Name</div>
<div>Last name</div>
<div>E-mail</div>
<div>Password</div>
<div>Confirm Password</div>
<div>phone no</div>
<div>Address</div>
<div>City</div>
<div>State</div>
<div>country</div>
<div>post code</div>
</td>
<td width="52" class="formtext-gap">
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
<div>:</div>
</td>
<td width="486" valign="top">
<div><input type="text" name="username_first"/></div>
<div><input type="text" name="username_last"/></div>
<div><input type="text" name="username_email"/></div>
<div><input type="text" name="username_pw"/></div>
<div><input type="text" name="username_cpw"/></div>
<div><input type="text" name="username_tele"/></div>
<div><input type="text" name="username_add"/></div>
<div><input type="text" name="username_city"/></div>
<div><input type="text" name="username_state"/></div>
<div><input type="text" name="username_country"/></div>
<div><input type="text" name="username_postcode"/></div>
</td>
</tr>
<tr><td colspan="3" align="center"><input type="checkbox"/> Terms and conditions of Discountlovers.in accpeted</td></tr>
<tr><td colspan="3" align="center"><div><input type="submit" value="Submit" class=""/></div></td></tr>
    </tbody></form></table></div>
<div><%@include file="footer.jsp" %></div>
</div>

</body>
</html>

------------------------ dies ist servlet einfügen von Daten------------------------

package registration_Servlets;


import registration_Servlets.intialization_form;
import java.io.IOException;
import java.io.PrintWriter;

import java.sql.PreparedStatement;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


/**
 * Servlet implementation class Registrationform
 */
@WebServlet("/Registrationform")
public class Registrationform extends HttpServlet {
    private static final long serialVersionUID = 1L;

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

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        response.setContentType("text/html");
          PrintWriter pw = response.getWriter();
        intialization_form obj = new intialization_form();
        String name;
        String lastname;
        String username_email;
        String username_pw ;
        String username_cpw;
        String id ;
        String username_add;
        String username_city ;
        String username_state;
        String username_country;
        String username_postcode;
        try {
            name  = request.getParameter("username_first");
            lastname = request.getParameter("username_last");
            username_email = request.getParameter("username_email");
            username_pw = request.getParameter("username_pw");
            username_cpw = request.getParameter("username_cpw");
            id = request.getParameter("username_tele");
            username_add = request.getParameter("username_add");
            username_city = request.getParameter("username_city");
            username_state = request.getParameter("username_state");
            username_country = request.getParameter("username_country");
            username_postcode = request.getParameter("username_postcode");
            DataBase db = new DataBase();
            PreparedStatement pst = db.getConnection().prepareStatement("insert into registrationinfo values(?,?,?,?,?,?,?,?,?,?,?)"); 
             pst.setString(1, name );
             pst.setString(2, lastname);
             pst.setString(3, username_email);
             pst.setString(4, username_pw);
             pst.setString(5, username_cpw); 
             pst.setString(6, id);
             pst.setString(7, username_add);
             pst.setString(8, username_city);
             pst.setString(9, username_state);
             pst.setString(10, username_country);
             pst.setString(11, username_postcode);
             int i = pst.executeUpdate();
             if(i==1){
                 //request.setAttribute("name",name);
                 /*String site = new String("Retrivin_user_reg_form");

                  response.setStatus(response.SC_MOVED_TEMPORARILY);
                  response.setHeader("Location", site); */
                 response.sendRedirect("Retrivin_user_reg_form");
             }
            pw.println("done");

    }
        catch (Exception e) {
             e.printStackTrace();
        }
}
    }

--------------------------------dies ist meine Daten abrufen servlet-----------------

package registration_Servlets;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Retrivin_user_reg_form
 */
@WebServlet("/Retrivin_user_reg_form")
public class Retrivin_user_reg_form extends HttpServlet {
    private static final long serialVersionUID = 1L;

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

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html");
          PrintWriter pw = response.getWriter();

        try {

            DataBase db = new DataBase();
            PreparedStatement pst = db.getConnection().prepareStatement("Select * from registrationinfo"); 
            intialization_form obj = new intialization_form();
             ResultSet i = pst.executeQuery();
             while(i.next()){
            //pw.println("EmpName" + " " + "EmpSalary" + "<br>");
             obj.name= i.getString(1);
             obj.lastname=i.getString(2);
             obj.username_email=i.getString(3);
             obj.username_pw=i.getString(4);
             obj.username_cpw=i.getString(5);
             obj.id=i.getString(6);
             obj.username_add=i.getString(7);
             obj.username_city=i.getString(8);
             obj.username_state=i.getString(9);
             obj.username_country=i.getString(10);
             obj.username_postcode=i.getString(11);
             String site = new String("registrationcompleted.jsp");

              response.setStatus(response.SC_MOVED_TEMPORARILY);
              response.setHeader("Location", site);
             /*request.getRequestDispatcher("registrationcompleted.jsp").forward(request, response);*/
             }
    }
        catch (Exception e) {
             e.printStackTrace();
        }

    }
      protected void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException {

        }

}

-----------das ist mein Java-Klasse, wo ich speichern möchte meine Daten abgerufen haben--------------

package registration_Servlets;

public class intialization_form
{
    String name;
    String lastname;
    String username_email;
     String username_pw;
     String username_cpw;
    String id;
    String username_add;
    String username_city;
    String username_state;
    String username_country;
    String username_postcode;

     public void setname( String value )
        {
         name = value;
        }
     public String getname() { return name; }

     public void setlastname( String value )
        {
         lastname = value;
        }
     public String getlastname() { return lastname; }

     public void setusername_email( String value )
        {
         username_email = value;
        }
     public String getusername_email() { return username_email; }

     public void setusername_pw(String value){
         username_pw= value;
     }
     public String getusername_pw() { return username_pw; }

     public void setusername_cpw(String value){
         username_cpw=value;
     }
     public String getusername_cpw(){
         return username_cpw;
     }
     public void setid(String value){
         id= value;
     }
     public String getid(){
         return id;
     }
     public void setusername_add(String value){
         username_add= value;
     }
     public String getusername_add(){
         return username_add;
     }
     public void setusername_city(String value){
         username_city= value;
     }
     public String getusername_city(){
         return username_city;
     }
     public void setusername_state(String value){
         username_state= value;
     }
     public String getusername_state(){
         return username_state;
     }
     public void setusername_country(String value){
         username_country = value;
     }
     public String getusername_country(){
         return username_country;
     }
     public void setusername_postcode(String value){
         username_postcode= value;
     }
     public String getusername_postcode(){
         return username_postcode;
     }


}

-------------------------das ist mein out-put-JSP-wo bekomme ich null Wert-------------

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
  <%@ page import = "registration_Servlets.intialization_form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>WELCOME TO DISCOUNTLOVERS.IN</title>



<script type="text/javascript" src="jquery-1.2.6.min.js"></script>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>

<body>
<div id="wrapper">
<div><%@include file="header.jsp" %></div>

<div><table width="920" border="0" cellpadding="0" cellspacing="0" id="main-content">
<tbody>
<tr>
<td>
<% intialization_form user = new intialization_form(); %>
first Name: <%= user.getname() %> 
last name: <%= user.getlastname() %><BR>
Email: <%= user.getusername_email() %><BR>
</td>
</tr>
    </tbody></table></div>
<div><%@include file="footer.jsp" %></div>
</div>

</body>
</html>
InformationsquelleAutor | 2013-06-30
Schreibe einen Kommentar