facebook

proper project structure

  1. MyEclipse IDE
  2.  > 
  3. Off Topic
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #318174 Reply

    David
    Member

    I have a webapp that I run REST services in Tomcat. However, I am unable to get the html pages to show up to use javascript or css. Here is my project structure:

    project
    – src
    – test
    – target
    –webapp
    —lib
    —css
    —–style.css
    —js
    —–myjs.js
    —home.html

    I do have resources/services defined for / and /office so perhaps that is why its not being caught? Here is my web.xml:

    <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>classpath:applicationContext.xml</param-value>
        </context-param>
        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>
        <listener>
            <listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
        </listener>
        <servlet>
            <servlet-name>MyServlet</servlet-name>
            <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>
              <init-param>
          <param-name>com.sun.jersey.config.property.packages</param-name>
          <param-value>com.xxx.yyy.resources</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>MyServlet</servlet-name>
            <url-pattern>/*</url-pattern>
        </servlet-mapping>

    I am hoping to use a html for each rest resource and pass JSON to it for JQuery. I would greatly appreciate any help or advice anyone can offer.

    #318202 Reply

    support-joy
    Member

    sonoerin,

    I am afraid the information you have given below is not enough for me to investigate this issue. What is the issue you are facing? What does your html show? Where have you declared your javascript / css. For debug purpose, could you move your javascript and css functions directly to your html to check if they render. Next verify the path of your javascript file and css file. You are facing development related issue. I would recommend you research on development forums

    #318348 Reply

    David
    Member

    I guess my question was really more about configuration. I used the wizard to setup a web service project, and I can use the created resources to actually receive a GET on the url. However, I would like to have a html page for each area so I can send/receive data back and forth. Probably I need a online tutorial that demonstrates:

    / (index.html would have javascript to send/receive data)
    /office would have an office.html that handles the request

    All the REST examples I have found seem to focus on the server side, but html or something must be on the UI – how do you set that up in the project?

    #318429 Reply

    support-tony
    Keymaster

    sonoerin,

    I’m not really sure what you’re trying to do. Web services, including ReST web services, is a means of communication between two machines, using HTTP (usually). Both ends need to write code to communicate. One end has the web service and the other has a program that uses that web service to obtain data or execute some functionality. It can be two server machines communicating or a server and a client program. MyEclipse provides tools that are, essentially, the client side of the communication, in order to test your service.

    An HTML page is just a front end to a web application, not a web service. If you want to display HTML pages, then a web application is appropriate, not a web service, since you are essentially communicating between a real user and the server. However, the web application, behind the HTML pages, can communicate with a web service to carry out its functionality.

    But I may be misunderstanding what you’re after. If my reply doesn’t give you any hints, could you explain what you want, in a different way, so we can better understand?

    #318435 Reply

    David
    Member

    My apologies for not explaining my project setup better.

    Server
    ——-
    Jersey/Spring/Hibernate

    Client
    ——-
    HTML/JSON/JQuery

    What I am trying to do is when a visitor hits a page, the URL calls the resource on the server, which will do some action, and return JSON data to the HTML, where JQuery will handle it. I really don’t want to use JSP, but when I try and run this, none of my html, css, or js gets applied. If I dynamically create html and return that, it does display, but again the html, css, and js are not.

    Perhaps I am going down the wrong path with the HTML/JQuery approach? II just wanted something other than JSP’s for this.

    #318457 Reply

    Brian Fernandes
    Moderator

    sonoerin,

    I’m assuming that you do not intend to return complete HTML from your web service calls; rather you have complete HTML + CSS + JS pages which internally make calls to the web service. The web service returns data in JSON which you use to dynamically populate part of your rendered page using jQuery. Is this correct?

    I think your problem may be the fact that you’re mapping all requests to your server through the REST servlet

       <servlet-mapping>
          <servlet-name>MyServlet</servlet-name>
          <url-pattern>/*</url-pattern>
       </servlet-mapping>

    I would recommend using a special pattern for your RESTful services, perhaps something like

       <servlet-mapping>
          <servlet-name>MyServlet</servlet-name>
          <url-pattern>/services/*</url-pattern>
       </servlet-mapping>

    Then change all the calls to the web services in your code to use this URL instead. For the client side, make sure URLs being presented and used do not use the services URL – they will then simply be directly returned by the web server and should therefore render just fine. Try a simple page with no web service calls but with JS and CSS, does that work?

Viewing 6 posts - 1 through 6 (of 6 total)
Reply To: proper project structure

This topic is marked as closed to new replies, however your posting capabilities still allow you to do so.

You must be logged in to post in the forum log in