I'm developing an application in JAVA where a servlet is taking the inputs from a JSP page. After inserting the values in db it will redirect to another servlet. Then the 2nd servlet will dispatch a JSP page with an ArrayList. But I can't redirect from the 2nd servlet to the JSP page. The ArrayList is going to the JSP page but the page is not showing anything. I'm using NetBeans 6.8.

Code for 1st Servlet:

RequestDispatcher dispatcher = request.getRequestDispatcher("/Servlet1?id="+id);
dispatcher.forward(request, response);

Code for 2nd Servlet:

request.setAttribute("list",list);
String url="test2.jsp";
RequestDispatcher v=request.getRequestDispatcher(""+url+"");
v.forward(request, response);

I've put a System.out.println("list values::"+list.get(0)); in the final JSP page. It is working and print the value which I can see in the output console in Netbeans. But the page is not displayed. The 2nd servlet is working properly when I'm accessing it directly. But when I'm accessing it through another servlet the problem is arises.

I'll be thankful if anyone can solve this problem.

Recommended Answers

All 2 Replies

Member Avatar for LastMitch

But I can't redirect from the 2nd servlet to the JSP page.

Can you post a little more than just those?

It should be something like this:

http://www.javapractices.com/topic/TopicAction.do?Id=181

Base on what you mention I think it's the path to the jsp file:

response.sendRedirect("/path/to/test2.jsp");

I cant get your question, 2nd servlet not redirect on jsp or 1st servlet not redirect to 2nd servlet?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.