Win a copy of The Way of the Web Tester: A Beginner's Guide to Automating Tests this week in the Testing forum!
    Bookmark Topic Watch Topic
  • New Topic

passing parameter from servlet to jsp

alona ariel
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Report post to moderator
I write a programm that pass parameter from jsp to servlet and than according to the parameter the servlet get pass back a parameter to the servlet. I think that the first stage work but the second stage does not work. I attach my code hopefully somebody will tell me what wrong with my code.explain to my programm in the first jsp(I dont attach) I have a radio button with value fruit that choose one fruit .
the servlet get the kind of fruit we choose and for example if the fruit is
an apple the servlet sent us to applestore.jsp with attribute to the jsp of appleshop. but it doesnt pass the parameter appleshop from the jsp to the servlrt.please somebody can help me

String fruit = request.getParameter("fruit");
PrintWriter out = response.getWriter();
System.out.println(" your choice "+fruit);

if ((fruit).equals("apple")){

String apple="appleshop";

javax.servlet.RequestDispatcher rd = this.getServletContext().getRequestDispatcher("/applestore.jsp");
rd.forward(request, response);
<% String fruit=(String)request.getAttribute("fruit");%>

your choice: <%= request%>
Bear Bibeault
Author and ninkuma
Posts: 65278
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
Please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
    Bookmark Topic Watch Topic
  • New Topic