• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

showing one jsp instead of other

 
Ravindranath Chowdary
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Friends,
I am developing a small application that is given in the HeadFirst Servlets and JSP. When i am trying to access one jsp i am getting the view of other jsp with out change in url.
http://localhost:8080/TestJSP/personal.jsp
For this it is showing hobby.jsp in the view.

In the web.xml the mapping is like this...

<servlet>
<servlet-name>MyFirstJSP</servlet-name>
<jsp-file>/hobby.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>ravindranath@pbsihyd.com</param-value>
</init-param>
</servlet>

<servlet>
<servlet-name>MyPersonalServlet</servlet-name>
<servlet-class>PersonalServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>MyPersonalServlet</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>MyPersonalServlet</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>MyFirstJSP</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

MyPersonalServlet.java:
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import foo.*;

public class PersonalServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
foo.Person p = new foo.Person();
p.setName("Evan");
request.setAttribute("person",p);

RequestDispatcher view = request.getRequestDispatcher("personal.jsp");
view.forward(request, response);
}
}

personal.jsp:
<html>
<body>
This is my Name:
<%= ((foo.Person) request.getAttribute("person")).getName() %>
</body>
</html>

The content it is showing in the browser is not the content i wrote in personal.jsp...it is of some other jsp.

Please clarify this doubt.

Thanks,
Ravindranath.
[ November 28, 2006: Message edited by: Bear Bibeault ]
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May I ask why you have two mappings for the "*.jsp" pattern ?
 
Ravindranath Chowdary
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Satou,
Yes, I wrote this *.jsp for two servlet-mappings. But, I changed the web.xml and tested again.....

web.xml:-

<servlet>
<servlet-name>MyPersonalServlet</servlet-name>
<jsp-file>/personal.jsp</jsp-file>
</servlet>

<servlet-mapping>
<servlet-name>MyPersonalServlet</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>


<servlet-mapping>
<servlet-name>MyFirstJSP</servlet-name>
<url-pattern>*.jsp</url-pattern>
</servlet-mapping>

<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
Can you please suggest me what to do? to come out of this issue.

Thanks,
Ravindranath.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're directing all JSP files to MyFirstJSP, which is a jsp file called "hobby.jsp".
If you want to redirect to MyPersonalServlet, maybe you should try
http://localhost:8080/TestJSP/personal.do
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic