1

I am working on a Java project on Spring framework. The project is cloned from the Heroku site. I encountered two issues...

  1. I have created a JSP file (testing.jsp) and committed + pushed to Heroku. I created it in src/main/webapp/WEB-INF/jsp/testing.jsp

    <servlet-name>spring</servlet-name>
    <url-pattern>/people/*</url-pattern>
    <url-pattern>/testing/*</url-pattern>
    

    I have edited it in web.xml file and pushed to Heroku. However, when I tried to view it in my browser, it shows me the same interface as the default people.jsp page.

My web.xml file: https://skydrive.live.com/redir?resid=2FC5994FBEB75CC5!174&authkey=!APyQGWZbKhkoAyM

  1. I have created a css file and pushed to Heroku. I have added the following...

    <link href="/imageCSS.css" rel="stylesheet">

    When I view in browser, it shows "HTTP Status 404 - /imageCSS.css"

    I am new to this and I can't seem to google anything useful that helps me in my issue.

Sky
  • 163
  • 2
  • 4
  • 15
  • Where is your `imageCSS.css` placed in your project hierarchy? Can you add your `spring-servlet.xml` in order to see your configuration? Which URL are you typing to display the css? – araknoid Aug 26 '13 at 07:50
  • I placed my imageCSS.css at the root... xxx/imageCSS.css The URL I want it to display is at the index.jsp when I load http://xxx.herokuapp.com/ – Sky Aug 26 '13 at 08:50
  • You should put your css under the `src/main/webapp/css` folder for example and the use the `` configuration in your `spring-servlet.xml` for scan. Give a look a this post [Spring 3 MVC resources and tag ](http://stackoverflow.com/questions/8195213/spring-3-mvc-resources-and-tag-mvcresources) – araknoid Aug 26 '13 at 08:55
  • I can't locate the spring-servlet.xml. The only xml files I can view from the projects are web.xml, pom.xml, applicationContext.xml, persistence.xml. They are all created by default. – Sky Aug 26 '13 at 08:57
  • Can you attach the content of your `applicationContext.xml`? – araknoid Aug 26 '13 at 08:58
  • https://skydrive.live.com/redir?resid=2FC5994FBEB75CC5!173&authkey=!AB1bjgOcO9toRIs – Sky Aug 26 '13 at 09:05

2 Answers2

1

You need to:

  1. Add the mvc:resources config in your applicationContext.xml like following:

    <mvc:resources mapping="/resources/**" location="/resources/" /> 
    
  2. Create a folder css under src/main/webapp/resources/, even the resources one if you haven't it.

  3. Link the ccs stylesheet in your jsp as following:

    <link rel="stylesheet" href="<c:url value="/resources/css/imageCSS.css" />">

  4. Remember to include also the JSTL taglig in your page:

    <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

For the point 1, you can't add multiple <url-pattern> to a single <servlet-mapping>. You should have something like this:

<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/people/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
    <servlet-name>spring</servlet-name>
    <url-pattern>/testing/*</url-pattern>
</servlet-mapping>
araknoid
  • 3,065
  • 5
  • 33
  • 35
  • I did exactly the above but it is not working too. When I viewed my browser, the text "> will appear on my page. – Sky Aug 26 '13 at 10:57
  • @user2707516 Have you imported the JSTL taglib? I edited my answer adding point 4. – araknoid Aug 26 '13 at 12:39
  • It works, really really appreciate it! That solved my 2nd issue, by any chance you know why my testing.jsp does not show up correctly? It seems to show the default people.jsp page even though I type in the correct address! – Sky Aug 26 '13 at 15:52
  • Edited the answer with more detail for the point 1. Glad to hear your problem got solved. :) – araknoid Aug 26 '13 at 18:16
  • Changing that didn't solve it. I am wondering is it because I am missing some files or coding somewhere? people.jsp is the default page. There are also PersonController.java, Person.java, PersonService.java, PersonServiceImpl.java created by default. Since it is not what I want, I added in a testing.jsp in the same folder as people.jsp. (src/main/webapp/WEB-INF/jsp/testing.jsp) Next, I modified the web.xml page. But my testing.jsp page will display the same page as people.jsp when I entered the url. – Sky Aug 28 '13 at 05:39
  • Added the link to my web.xml in my first post. imageenhance is the testing I am referring to. – Sky Aug 28 '13 at 05:46
  • Which url are you calling to display? Have you mapped it with any controller? – araknoid Aug 28 '13 at 07:17
  • I am trying to load http://xxx.herokuapp.com/imageenhance/ I don't think I have mapped it to any controllers. May I ask how to map onto one? I am using spring framework. – Sky Aug 28 '13 at 08:00
  • There should be a controller that is mapping a request with `value="/"` and that is why you are displaying the people.jsp page because it will map xxx.com/imageenhance and xxx.com/people as the same. You have to add a new controller in the `com.example` package. Give a check at point 2 of this [example](http://www.mkyong.com/spring-mvc/spring-mvc-hello-world-annotation-example/). – araknoid Aug 28 '13 at 08:46
  • I changed @RequestMapping("/") found in PersonController to @RequestMapping("/people"). I also added a new ImageController with @RequestMapping("/imageenhance"). Now when I access xxx.com/imageenhance, it shows HTTP Status 404 - The requested resource is not available. – Sky Aug 28 '13 at 09:17
  • Since you have configured the `url-pattern` with `/people/*` and the `PersonController` request mapping as `"/people"` you need to call `xxx.com/people/people` to have it invoked. To solve this and use the `xx.com/people` url, remove your servlet-mapping and use this: ` spring / ` – araknoid Aug 28 '13 at 09:23
  • The people.jsp is working as per norm. But I will hit the 404 error on my imageenhance.jsp. Perhaps I attached the files for easy reference. imageenhance (https://skydrive.live.com/redir?resid=2FC5994FBEB75CC5!175&authkey=!ADmUTym0a1JuymU) and people (https://skydrive.live.com/redir?resid=2FC5994FBEB75CC5!182&authkey=!AKcpGeJiegnn2gw) and updated web.xml (https://skydrive.live.com/redir?resid=2FC5994FBEB75CC5!183&authkey=!ALt6JhNlQasGj94) – Sky Aug 30 '13 at 08:55
0

I managed to solve my first issue. I don't really know where the exact problem lies on but I believe it is either I didn't map the request correctly in my controller class initially or I didn't implement out the methods and model class for that controller in order for everything to function properly.

Thanks for all the helps, really appreciate.

Sky
  • 163
  • 2
  • 4
  • 15