Redirecting from jsp to servlet,and back to original jsp

I have a index.jsp page that i need to pass information from to a servlet, but i then need the servlet to redirect me back to the index.jsp page displaying the new data.Is this possible? And where should i place the code,within the doPost,doGet or the method that is processing the data from the bean.When i click on "Add" in jsp it is directing to servlet URL but it is a blank page displaying nothing

here is my list_add code

private void listAdd(String newTeam, HttpServletRequest request, HttpServletResponse response) throws ServletException,IOException   //process Add request from browser
   {
         FootyManager manager = null; //create instance of class
           
         
           

         try

         {
               manager = getFootyManager();  //call method to get connection
               manager.addNewTeamToList(new Team(1, newTeam)); //pass parameters to method
                   RequestDispatcher rd = getServletContext().getRequestDispatcher("MyWeb/web/index.jsp");
                   rd.forward(request, response);
         }

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

         finally
         {
               if (manager != null)
               {
                    
                           
                           manager.releaseResources();

               }
                 
                   

         }

Regards,
Styx218
Styx218Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Mayank SAssociate Director - Product EngineeringCommented:
>> RequestDispatcher rd = getServletContext().getRequestDispatcher("MyWeb/web/index.jsp");

Perhaps the URL there is wrong. What is the URL pattern of the servlet?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Styx218Author Commented:
<servlet-name>AdminServlet</servlet-name>
 <url-pattern>/AdminServlet</url-pattern>
0
Mayank SAssociate Director - Product EngineeringCommented:
the web app context is /MyWeb?

Maybe try: getRequestDispatcher ( "/web/index.jsp" ) ;
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

Styx218Author Commented:
Hi, Thanks for your suggestions,but i have a new issue, i have altered my code but i am now getting following error when trying to load my jsp page

"Can't find a method to write property 'name' of type 'java.lang.String' in a bean of type 'com.football.Team'"

My bean code is
package com.football;

import java.beans.*;
import java.io.Serializable;

public class Team  implements Serializable
{
    private int    id;
    private String name;

    public Team()
    {
        id = id;
        name = name;
    }

    public int getId()
    {
        return id;
    }

    public String getName()
    {
        return name;
    }

    public boolean equals(Object obj)
    {
        if (obj instanceof Team)
        {
            Team compare = (Team)obj;
            return (id == compare.getId());
        }
        return false;
    }

    public int hashCode()
    {
        return name.hashCode();
    }

    public String toString()
    {
        return getClass() + "[" + id + "] : [" + name + "]";
    }



    private void setId(int id)
    {
        id = id;
    }

    private void setName(String name)
    {
        name = name;
    }
}

My bean declaration in index.jsp is as follows

<jsp:useBean id = "newTeam" class = "com.football.Team" scope ="request" />
<jsp:setProperty name = "newTeam" property = "name" value = "name" />

i feel i am getting closer to solving this, but i cant use the <jsp:getProperty in the AdminServlet as its a .java file. Any idea as to where i should go from here?

Regards,
Styx218
0
Mayank SAssociate Director - Product EngineeringCommented:
Did you compile that class? Is its class file present in the WEB-INF/classes/com/football directory? Try restarting the server once after compiling it and then try - the class contains a getName () method so it should fine once the server loads it.
0
Styx218Author Commented:
Hi, Recompiled the class,restarted server and still same issue

my class file is contained within MyWeb\build\web\WEB-INF\classes\com\football as i am using NetBeans along with all other java class files..
0
Styx218Author Commented:
I have taken out the jsp:setProperty which seems to have removed the error,but i am now getting

C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\footy\MyWeb\src\java\com\football\AdminServlet.java:134: cannot find symbol
symbol  : constructor Team(int,java.lang.String)
location: class com.football.Team
                   manager.addNewTeamToList(new Team(0, newTeam)); //pass parameters to method

My Team constructor is as follows??
public Team()
    {
        id = id;
        name = name;
    }

?????
0
Styx218Author Commented:
Any ideas?
0
Styx218Author Commented:
Can anyone help me with this? Surely its not too hard of an issue?
0
KuldeepchaturvediCommented:
>>symbol  : constructor Team(int,java.lang.String)
location: class com.football.Team
                   manager.addNewTeamToList(new Team(0, newTeam));


in there you are trying to do a new Team(0,newTeam); which means system is looking for a constructer with a signature like

public Team(int i, String name)

which you do not have in class "Team" and hence the error is correct.
0
elissaqpCommented:
why redirecting to the same page? why on the servlet create the result you want? A servlet will show a blank page if you do not tell it what  to show.
As simple as adding this code on your servlet:
out.println("<html>");
out.println("<body>");
out.println("hello world!!!");
out.println("</body>");
out.println("</html>");
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java EE

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.