Anubis13 Δημοσ. 14 Ιουνίου 2012 Δημοσ. 14 Ιουνίου 2012 >// Using Session import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class HolidaysSelection extends HttpServlet { public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException { PrintWriter output; HttpSession session = request.getSession(false); if (session==null) { session = request.getSession(true); String name = request.getParameter( "FirstName" )+" "+request.getParameter( "LastName" ); String phone = request.getParameter( "phone" ); String country = request.getParameter( "country" ); String mail = request.getParameter( "email" ); String type = request.getParameter( "selection" ); session.setAttribute("name", name); session.setAttribute("phone", phone); session.setAttribute("country", country); session.setAttribute("email",mail); session.setAttribute("type", type); } String name = session.getAttribute("name").toString(); String phone = session.getAttribute("phone").toString(); String country = session.getAttribute("country").toString(); String type = session.getAttribute("type").toString(); response.setContentType( "text/html" ); output = response.getWriter(); if (type.equals("New York")) { output.println( "<HTML><HEAD><TITLE>" ); output.println( "Hotel Selection in New York"); output.println( "</TITLE></HEAD><BODY>" ); output.println( "<h1>Hotel Selection in New York</h1>"); output.println( "<P>Thank you for selecting one of our offers, "+name); output.println( "!</P>The following list includes our 5* hotels you can choose from:<br><br>"); output.println( "<table border=\"1\">"); output.println( "<tr>"); output.println( "<th>Hotel Name</th><th>Description</th>"); output.println( "</tr>"); output.println( "<tr>"); output.println( "<td>Trump Soho New York</td><td>This luxury hotel is a block from the New York City Fire Museum and within three-quarters of a mile of the Children’s Museum of the Arts and Washington Square Park Price: £244</td>"); output.println( "</tr>"); output.println( "<tr>"); output.println( "<td>The Surrey</td><td>Situated in the Upper East Side neighborhood of New York, The Surrey is near Central Park, the Whitney Museum of American Art, and Metropolitan Museum of Art. Steps away from Madison Avenue Shopping., Price: £230</td>"); output.println( "</tr>"); output.println( "<tr>"); output.println( "<td>The Towers at The New York Palace</td><td>This luxury hotel is located in the heart of New York, walking distance from St. Patrick's Cathedral, Rockefeller Center, and Museum of Modern Art. Also nearby are Grand Central Terminal and Chrysler Building, Price: £315</td>"); output.println( "</tr>"); output.println( "</table>"); output.println("<br> <font>Please choose the model you prefer:</font> <br>"); output.println( " <form action='http://localhost:8080/Exercise1/ConfirmSelection' method='POST'> " ); output.println(" <input type='radio' name='choice' value='Trump Soho New York'/>Trump Soho New York <BR>"); output.println(" <input type='radio' name='choice' value='The Surrey'/>The Surrey <BR>"); output.println(" <input type='radio' name='choice' value='The Towers at The New York Palace'/>The Towers at The New York Palace"); output.println("<BR> <BR> <input type='submit' value='SUBMIT'>"); } if (type.equals("Hawai")) { output.println( "<HTML><HEAD><TITLE>" ); output.println( "Hotel Selection in Hawai"); output.println( "</TITLE></HEAD><BODY>" ); output.println( "<h1>Hotel Selection in Hawai</h1>"); output.println( "<P>Thank you for selecting one of our offers, "+name); output.println( "!</P>The following list includes our 5* hotels you can choose from:<br><br>"); output.println( "<table border=\"1\">"); output.println( "<tr>"); output.println( "<th>Hotel Name</th><th>Description</th>"); output.println( "</tr>"); output.println( "<tr>"); output.println( "<td>Four Seasons Resort Hualalai</td><td>Nestled along the Kona-Kohala Coast with a private beach, the luxury resort is 7 mi (11 km) from the airport, Price: $645</td>"); output.println( "</tr>"); output.println( "<tr>"); output.println( "<td>The Kahala Resort and Spa</td><td>Get away from the hustle and bustle with this exclusively private retreat. A glamorous way to spend your tropical vacation, this secluded resort sits atop secret beaches and tranquil waters., Price: $575</td>"); output.println( "</tr>"); output.println( "<tr>"); output.println( "<td>The Halekulani Hotel</td><td>Catering to some of Hawaii's wealthiest visitors, this sophisticated hotel will lavish you with indulgence. Vacation at this beachfront location and enjoy exceptional cuisine, gracious hospitality, and unequaled splendor., Price: $600</td>"); output.println( "</tr>"); output.println( "</table>"); output.println("<br> <font>Please choose the model you prefer:</font> <br>"); output.println( " <form action='http://localhost:8080/Exercise1/ConfirmSelection' method='POST'> " ); output.println(" <input type='radio' name='choice' value='our Seasons Resort Hualalai'/>Four Seasons Resort Hualalai<BR>"); output.println(" <input type='radio' name='choice' value='The Kahala Resort and Spa'/>The Kahala Resort and Spa<BR>"); output.println(" <input type='radio' name='choice' value='The Halekulani Hotel'/> The Halekulani Hotel"); output.println("<BR> <BR> <input type='submit' value='SUBMIT'>"); } output.println( "</BODY></HTML>" ); output.close(); // close stream } } Καλησπερα, λοιπον εχω αυτο το java αρχειο που φτιαχνει μια φορμα και εχει μια επιλογη. Ολα δουλευουν καλα αλλα οταν γυρισω απο τη δευτερη σελιδα σε αυτη της φορμας, αλλαξω τα στοιχεια και πατησω submit τοτε κραταει τα αρχικα στοιχεια. Δεν μπορω να το κανω να ανανεωνει τα στοιχεια την δευτερη φορα. Καμμια ιδεα?
Anubis13 Δημοσ. 15 Ιουνίου 2012 Μέλος Δημοσ. 15 Ιουνίου 2012 Κανείς δεν έχει καμιά ιδέα τι παίζει με το session?
Προτεινόμενες αναρτήσεις
Δημιουργήστε ένα λογαριασμό ή συνδεθείτε για να σχολιάσετε
Πρέπει να είστε μέλος για να αφήσετε σχόλιο
Δημιουργία λογαριασμού
Εγγραφείτε με νέο λογαριασμό στην κοινότητα μας. Είναι πανεύκολο!
Δημιουργία νέου λογαριασμούΣύνδεση
Έχετε ήδη λογαριασμό; Συνδεθείτε εδώ.
Συνδεθείτε τώρα