Link to home
Start Free TrialLog in
Avatar of tlDeveloper
tlDeveloper

asked on

Web browser tries to load page with .jsp.jsp extension rather than .jsp extension in Java web application




I am developing a web app using java tools and Tomcat.  I type the following into my browser: http://localhost:7777/bikestore/bikes.bikes , and this is supposed to load the page bikes.jsp but instead I get the following message in my browser:

HTTP Status 404 - /bikes.jsp.jsp

type Status report

message /bikes.jsp.jsp

description The requested resource (/bikes.jsp.jsp) is not available.
Apache Tomcat/5.5.16





Here are some other relevant files:


web.xml:

<!DOCTYPE web-app
 PUBLIC  "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
 "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
 <taglib>
   <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
   <taglib-location>/WEB-INF/lib/c.tld</taglib-location>
 </taglib>
 <taglib>
    <taglib-uri>/spring</taglib-uri>
    <taglib-location>/WEB-INF/lib/spring.tld</taglib-location>
  </taglib>

 <servlet>
    <servlet-name>rentaBikeApp</servlet-name>
    <servlet-class>
      org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <load-on-startup>1</load-on-startup>
 </servlet>
 <servlet-mapping>
    <servlet-name>rentaBikeApp</servlet-name>
    <url-pattern>*.bikes</url-pattern>
 </servlet-mapping>
</web-app>





rentaBikeApp-servlet.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>
   <bean id="rentaBike" class="com.springbook.ArrayListRentABike">
      <property name="storeName"><value>Bruce's Bikes</value></property>
   </bean>
   <bean id="bikesController" class="com.springbook.BikesController">
      <property name="facade"><ref bean="rentaBike"/></property>
   </bean>
   <bean id="editBikeController" class="com.springbook.EditBikeController">
      <property name="facade"><ref bean="rentaBike"/></property>
   </bean>
   <bean id="submitBikeController" class="com.springbook.SubmitBikeController">
      <property name="facade"><ref bean="rentaBike"/></property>
   </bean>
   <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
      <property name="mappings">
         <props>
            <prop key="/bikes.bikes">bikesController</prop>
            <prop key="/editBike.bikes">editBikeForm</prop>
            <prop key="/newBike.bikes">editBikeForm</prop>
         </props>
      </property>
   </bean>
   <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
      <property name="viewClass">
         <value>org.springframework.web.servlet.view.JstlView</value>
      </property>
      <property name="suffix">
         <value>.jsp</value>
      </property>
   </bean>
   <bean id="bikeValidator" class="com.springbook.BikeValidator"/>
   <bean id="editBikeForm" class="com.springbook.SubmitBikeController">
      <property name="sessionForm"><value>true</value></property>
      <property name="commandName"><value>bike</value></property>
      <property name="commandClass"><value>com.springbook.Bike</value></property>
      <property name="validator"><ref bean="bikeValidator"/></property>
      <property name="formView"><value>editBike</value></property>
      <property name="successView"><value>bikes.bikes</value></property>
      <property name="facade"><ref bean="rentaBike"/></property>
   </bean>
</beans>




RentABike-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

      <bean id="rentaBike" class="com.springbook.ArrayListRentABike">
            <property name="storeName"><value>"Bruce's Bikes"</value></property>
      </bean>
      
      <bean id="commandLineView" class="com.springbook.CommandLineView">
            <property name="rentaBike"><ref bean="rentaBike" /></property>
      </bean>
      
</beans>












I am unable to figure out why the browser is trying to load bikes.jsp.jsp rather than bikes.jsp.  I would greatly appreciate any suggestions.  Please let me know if there are other files which I can provide.






Avatar of Mick Barry
Mick Barry
Flag of Australia image

EditBikeController  should be return viewname as bikes, not bikes.jsp
Avatar of tlDeveloper
tlDeveloper

ASKER


I am unable to find anywhere where I wrote "bikes.jsp".  Where do I return the viewname as bikes.jsp? What should I be editting?

can u post com.springbook.EditBikeController

EditBikeController.java:



package com.springbook;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class EditBikeController implements Controller {
    private RentABike facade;

    public RentABike getFacade() {
        return facade;
    }

    public void setFacade(RentABike facade) {
        this.facade = facade;
    }

    public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws Exception {
        if(request.getParameter("bikeSerialNo") == null) {
            System.out.println("bikeSerialNo was null");
            return new ModelAndView("editBike");
        } else {
            System.out.println("bikeSerialNo == " + request.getParameter("bikeSerialNo"));
            Bike bike = facade.getBike(request.getParameter("bikeSerialNo"));
            return new ModelAndView("editBike", "bike", bike);
        }

    }
}
what does editBike.jsp look like

editBike.jsp:

<%@ page isELIgnored="false" import="com.springbook.*" %>
<%@ include file="include.jsp" %>
<%@ taglib prefix="spring" uri="/spring" %>

<html>
    <head>
        <title>
            Edit Bike
        </title>
    </head>
    <body>
        <h1>Edit Bike</h1>
        <form method="POST">
              <spring:hasBindErrors name="bike">
                <b>Please fix all errors!</b>
              </spring:hasBindErrors>
            <table border="1" cellspacing="2" cellpadding="2">
                <tr>
                    <td align="right">Manufacturer:</td>
                    <td>
                        <spring:bind path="bike.manufacturer">
                        <input type="text" name="manufacturer" value="<c:out value="${status.value}"/>"><font color="red"><c:out value="${status.errorMessage}"/></font>
                        </spring:bind>
                    </td>
                </tr>
                <tr>
                    <td align="right">Model:</td>
                    <td>
                        <spring:bind path="bike.model">
                        <input type="text" name="model" value="<c:out value="${status.value}"/>"><font color="red"><c:out value="${status.errorMessage}"/></font>
                        </spring:bind>
                    </td>
                </tr>
                <tr>
                    <td align="right">Frame:</td>
                    <td>
                        <spring:bind path="bike.frame">
                        <input type="text" name="frame" value="<c:out value="${status.value}"/>"><font color="red"><c:out value="${status.errorMessage}"/></font>
                        </spring:bind>
                    </td>
                </tr>
                <tr>
                    <td align="right">Serial Number:</td>
                    <td>
                        <spring:bind path="bike.serialNo">
                        <input type="text" name="serialNo" value="<c:out value="${status.value}"/>"><font color="red"><c:out value="${status.errorMessage}"/></font>
                        </spring:bind>
                    </td>
                </tr>
                <tr>
                    <td align="right">Weight:</td>
                    <td>
                        <spring:bind path="bike.weight">
                        <input type="text" name="weight" value="<c:out value="${status.value}"/>"><font color="red"><c:out value="${status.errorMessage}"/></font>
                        </spring:bind>
                    </td>
                </tr>
                <tr>
                    <td align="right">Status:</td>
                    <td>
                        <spring:bind path="bike.status">
                        <input type="text" name="status" value="<c:out value="${status.value}"/>"><font color="red"><c:out value="${status.errorMessage}"/></font>
                        </spring:bind>
                    </td>
                </tr>
            </table>
            <input type="submit" value="Submit">
        </form>
    </body>
</html>


I am thinking that the error is being caused by something other than the edit pages because the bikes are not being edited yet.  bikes.bikes should load bikes.jsp which lists all the available bikes and let's you click one to edit which should then load editBikes.jsp but it is not getting that far so it might be that editBikes/editBikeController would not be causing the error.  Though, I am a newbie so I could be totally wrong.

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial

Yes, that had it.  This is the file:

package com.springbook;

import org.springframework.web.servlet.mvc.Controller;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletRequest;


public class BikesController implements Controller {
    private RentABike facade;

    public RentABike getFacade() {
        return facade;
    }

    public void setFacade(RentABike facade) {
        this.facade = facade;
    }

    public ModelAndView handleRequest(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws Exception {
        return new ModelAndView("bikes.jsp", "rentaBike", facade);
    }
}


I changed bikes.jsp to bikes and now it works.  Thank you for your help.

no worries :)