See my comments below; Any sufficiently advanced technology is indistinguishable from magic - Author C Clark
________________________________ From: Rafał Laczek <rafal_lac...@wp.pl> To: dillanferna...@yahoo.com Cc: Java EE (J2EE) Programming with Passion! <java-ee-j2ee-programming-with-passion@googlegroups.com> Sent: Tue, January 5, 2010 9:00:22 AM Subject: Re: [java ee programming] JSP/Servlet Hi, Thanks for response. My comments are in // tags Can you help BR Rafal resultEdit.jsp - <form name="edit" action="ResultEdit.java" method="get"> You need to give the servlet name and not the java file name (what you have given in your web.xml) // I have changed for <form name="edit" action="ResultEdit" method="get"> ResultEdit.java - String action = request.getParameter("do"); You have passed "do" to the jsp file, but you haven't sent it to the Servlet. User a "hidden" field to send to the servlet. // I don't understand exactly what I should to do. Could you help me please. //I send bellow web.xml <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> <servlet> <servlet-name>Result</servlet-name> <servlet-class>servlets.Result</servlet-class> </servlet> <!-- Add the following-> <servlet> <servlet-name>ResultEdit</servlet-name> <servlet-class>servlets.ResultEdit</servlet-class> </servlet> <!-- End --> <servlet-mapping> <servlet-name>Result</servlet-name> <url-pattern>/Result</url-pattern> </servlet-mapping> <!-- Add The Following --> <servlet-mapping> <servlet-name>ResultEdit</servlet-name> <url-pattern>/ResultEdit</url-pattern> </servlet-mapping> <!-- End --> </web-app> In your resultEdit.jsp file after the following line <input type="hidden" name="id" value="<%=person.getId()%>"> type; <input type="hidden" name="do" value='<%=request.getParameter("do")%>'> Dnia 4-01-2010 o godz. 21:43 Dillan Fernando napisał(a): >You have not posted web.xml. But from what I can see, the following are >possible causes; > >resultEdit.jsp >- <form name="edit" action="ResultEdit.java" method="get"> >You need to give the servlet name and not the java file name (what you have >given in your web.xml) > > >ResultEdit.java >- String action = request.getParameter("do"); >You have passed "do" to the jsp file, but you haven't sent it to the Servlet. >User a "hidden" field to send to the servlet. > > >hope this helps > > > > Any sufficiently advanced technology is indistinguishable from magic - Author > C Clark > > > > ________________________________ From: Rafał Laczek <rafal_lac...@wp.pl> >To: Java EE (J2EE) Programming with Passion! ><java-ee-j2ee-programming-with-passion@googlegroups.com> >Sent: Mon, January 4, 2010 2:35:21 PM >Subject: [java ee programming] JSP/Servlet > >Hi >Colleagues, >I need your some help. >In reference to my last e-mail I ask you to help me with test application. >The idea is that after proper log in procedure the user will see the >list with some sample states. >Then there will be possibility to add, edit and delete the records. >At this moment there is possibility to add new records. Also when the >user clicks for edit button the list /table appears where there is >possibility to edit chosen record. >Unfortunately after clicking for save >button the edited record is without changes as well as in browser >following communicate appears: >TestApplication/ResultEdit.java >description The requested resource (/TestApplication/ResultEdit.java) is >not available. >Bellow I give you code of each file BUT PLEASE MAINLY CHECK >resulEdit.jsp and resultEdit.java(2 last files) because here is any >problem. > >Thank you for your help! > >Best >regards, >Rafal Laczek > >result.jsp - responsible for displaying list with registered records- >it works good. ><body> ><h3 style='font-size:40px' align='center';>Test Application</h3> ><div class="results"> ><table border="1"; style="height: 40px;width: 500px; background:white;" > ><tr><th colspan="7"><strong>Results:</strong></th></tr> > <tr> > ><td><strong>ID</strong></td> > <td><strong>First name</strong></td> > <td><strong>Surname</strong></td> > <td><strong>Sex</strong></td> > <td><strong>Country</strong></td> > <td> </td> > <td> </td> > </tr> > > <%/*ListIterator it = >arraylist.listIterator(); > while (it.hasNext()){ > Person person =(Person)it.next();*/%> > > <% ArrayList persons = (ArrayList)session.getAttribute("persons"); > if (persons != null) > > for (Iterator it = persons.iterator(); it.hasNext();){ > Person person =(Person)it.next();%> > ><tr> > <td> > ><%=session.getId()%> > </td> > <td> > <% out.println(person.getFirstName());%> > </td> > <td> > <%out.println(person.getSurname());%> > </td> > <td> > <%out.println(person.getSex());%> > </td> > <td> > ><%out.println(person.countryType());%> > </td> > > <% > out.println("<td><a href=\"ResultEdit.jsp?do=edit&id=" + person.getId() >+"\">Edit</td>"); > out.println("<td><button><a href=>Delete</a></button></td>"); > out.println("</tr>"); > %> > </tr> > <%} > else > out.println("List is empty");%> ></table> > > >Result.java - the servlet responsible for business logic. It works good. >package servlets; > >import java.io.*; >import java.util.*; >import javax.servlet.*; >import javax.servlet.http.*; > >import Testapplication.Person; > >public class Result extends HttpServlet{ > public void doGet(HttpServletRequest request, HttpServletResponse > >response)throws IOException, ServletException{ > this.doPost(request,response); > } > public void doPost(HttpServletRequest request, HttpServletResponse >response)throws IOException, ServletException{ > > HttpSession session = request.getSession(); > ArrayList<Person>persons = >(ArrayList)session.getAttribute("persons"); > > if(persons == null){ > persons = new ArrayList<Person>(); > > session.setAttribute("persons", persons); > } > > String firstName = request.getParameter("firstName"); > String >surname = request.getParameter("surname"); > String sex = request.getParameter("sex"); > String countryType = request.getParameter("countryType"); > if(firstName !=null && surname !=null){ > int idCounter = persons.size(); > Person person = new Person(idCounter); > > person.setFirstName(firstName); > person.setSurname(surname); > person.setSex(sex); > person.setCountryType(countryType); > //The object person1 is added to arraylist > persons.add(person); > > RequestDispatcher dispatcher = >request.getRequestDispatcher("/result.jsp"); > dispatcher.forward(request,response); > } > > } >} > >resultEdit.jsp it is possible to edit data but edited record is not >saved in arraylist. ><% >ArrayList<Person>persons = >(ArrayList)session.getAttribute("persons"); > >String indexS = request.getParameter("id"); >int index =Integer.parseInt(indexS); >Person person = persons.get(index); > >%> > ><form name="edit" action="ResultEdit.java" method="get"> ><table border="1"> ><tbody> ><tr> ><td>First name:</td> ><td><input type="text" name="firstName" >value="<%=person.getFirstName()%>"></td> ></tr> ><tr> ><td>Surname:</td> ><td><input type="text" name="surname" >value="<%=person.getSurname()%>"></td> ></tr> ><tr> ><td>Sex:</td> ><td><input type="text" name="sex" value="<%=person.getSex()%>"></td> ></tr> ><tr> ><td>Preferable country to live:</td> ><td><input type="text" name="countryType" >value="<%=person.countryType()%>"></td> ></tr> ></tr> ><tr> ><td colspan="2"><input type="submit" >name="btnSave" value="Save"></td> ></tr> ></tbody> ></table> ><input type="hidden" name="id" value="<%=person.getId()%>"> ></form> ></body> ></html> > >resultEdit.java serwlet. There is something wrong. >import >java.io.IOException; >import java.util.ArrayList; > >import javax.servlet.RequestDispatcher; >import javax.servlet.ServletException; >import javax.servlet.http.HttpServlet; >import javax.servlet.http.HttpServletRequest; >import javax.servlet.http.HttpServletResponse; >import javax.servlet.http.HttpSession; > >import Testapplication.Person; > >public class ResultEdit extends HttpServlet { > public void >doGet(HttpServletRequest request, HttpServletResponse >response) > throws ServletException, IOException { > > HttpSession session = request.getSession(); > ArrayList<Person>persons = (ArrayList)session.getAttribute("persons"); > > String action = request.getParameter("do"); > > if(action.equals("edit")){ > session.setAttribute("persons", >persons); > request.setAttribute("persons", persons); > RequestDispatcher dispatcher = >getServletContext().getRequestDispatcher("/result.jsp"); > dispatcher.forward(request, response); > }else if(action.equals("delete")){ > > response.sendRedirect(request.getContextPath() + "/result.jsp"); > } > } >} > >---------------------------------------------------- >Kibicuj biało-czerwonym w Zakopanem >Największa impreza sportowa tej zimy! >Zobacz zdjęcia: >http://klik.wp.pl/?adr=http%3A%2F%2Fcorto.www.wp.pl%2Fas%2Fskoki_galeria.html&sid=942 > > >-- >You received this message because you are subscribed to the Google >Groups "Java EE (J2EE) >Programming with Passion!" group. >To post to this group, send email to >java-ee-j2ee-programming-with-passion@googlegroups.com >To unsubscribe from this group, send email to >java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com >For more options, visit this group at >http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en > > >-- >You received this message because you are subscribed to the Google >Groups "Java EE (J2EE) Programming with Passion!" group. >To post to this group, send email to >java-ee-j2ee-programming-with-passion@googlegroups.com >To unsubscribe from this group, send email to >java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com >For more options, visit this group at >http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en ---------------------------------------------------- Kibicuj biało-czerwonym w Zakopanem Największa impreza sportowa tej zimy! Zobacz zdjęcia: http://klik.wp.pl/?adr=http://corto.www.wp.pl/as/skoki_galeria.html&sid=942 -- You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en
-- You received this message because you are subscribed to the Google Groups "Java EE (J2EE) Programming with Passion!" group. To post to this group, send email to java-ee-j2ee-programming-with-passion@googlegroups.com To unsubscribe from this group, send email to java-ee-j2ee-programming-with-passion+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/java-ee-j2ee-programming-with-passion?hl=en?hl=en