This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes JSP and the fly likes showing one jsp instead of other Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "showing one jsp instead of other" Watch "showing one jsp instead of other" New topic
Author

showing one jsp instead of other

Ravindranath Chowdary
Ranch Hand

Joined: Nov 08, 2006
Posts: 71
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

May I ask why you have two mappings for the "*.jsp" pattern ?


[My Blog]
All roads lead to JavaRanch
Ravindranath Chowdary
Ranch Hand

Joined: Nov 08, 2006
Posts: 71
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

Joined: Nov 24, 2005
Posts: 14688
    
  16

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
 
GeeCON Prague 2014
 
subject: showing one jsp instead of other