Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am developing simple Dynamic Web Project.
Env details:
Eclipse-Kepler (Java 1.6) with
apache tomcat 6.0 server.
My project structure is as follows:
Under WebContent/jsps folder i have:
home.jsp
listcenters.jsp
center.jsp
Under /src/com/myexample/controller i have:
CenterController.java --Servlet
Code in home.jsp as follows:
HTML
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My App</title>
</head>
<body>
<h1>Welcome to My App!</h1>
 <a href="CenterController?action=listcenters">Centers List</a>
</body>
</html>

My Web.xml has following mapping:
XML
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>MyApp</display-name>
  <welcome-file-list>
    <welcome-file>home.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
    <servlet-name>CenterController</servlet-name>
    <servlet-class>com.scms.controller.CenterController</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>CenterController</servlet-name>
    <url-pattern>/CenterController</url-pattern>
  </servlet-mapping>


Now my question is:
When i try to run my project, home page appears correctly with: localhost:port/MyApp/jsps/home.jsp
But when i click on hyperlink - Centers List, the application looks for servlet in same /jsps folder: http://localhost:port/MyApp/jsps/CenterController?action=listcenters and i get HTTP Status - 404 "requested resource not available."

Here is list of trial and error I did:

What I have tried:

Trial#1:
I tried changing the URL in anchor tag in home.jsp: from -
HTML
<a href="CenterController?action=listcenters">Centers List</a>

to
HTML
<a href="../CenterController?action=listcenters">Centers List</a>

This works well and I am redirected to listcenter.jsp On listcenter.jsp again I have an anchor tag to go back to home page with code as follows:
HTML
<a href="CenterController?action=gohome">Go Home</a>

This hypelink works well too. But problem starts after this. Now again if i try to click on Center List hyperlink, I get HTTP Status - 404 "requested resource not available." with URL as : http://localhost:9090/CenterController?action=listcenters. Here context root is missing.

Trial#2:
Keep url for Centers List as previous i.e. :
HTML
<a href="CenterController?action=listcenters">Centers List</a>

and tried changing Deploy path in Project's Web Deployment Assembly structure: I added Source - /WebContent/jsps and Deploy Path='/' This worked and all forward and backward and again forward navigation worked well.
But this caused all jsps in /jsps folder to be deployed under /WebContent folder. I don't want this. This is messy. And also, I don't think this is a full proof solution. Please help.
Posted
Comments
SanketAB 25-May-17 3:47am    
Any answer for this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900