English 中文(简体)
春季和休息
原标题:spring and rest
  • 时间:2012-01-12 05:52:49
  •  标签:
  • spring
  • rest

我制定了以下法典,但我似乎有以下错误:“当我使用“http:// localhost:80/restchildren/service/employees/1”进入该服务时,没有发现与URI公司(URI/restmers/service/employees/1)合用姓名的异构体Servlet,“当我使用“http:// localhost:80/restmers/service/employees/1”查询。 我是否误解了什么?

web.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" 
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
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">
<servlet>
    <servlet-name>restspring</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>restspring</servlet-name>
    <url-pattern>/service/*</url-pattern>
</servlet-mapping>
</web-app>

restspring-servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">

<bean id="jaxbMarshaller" class="org.springframework.oxm.jaxb.Jaxb2Marshaller">
<property name="classesToBeBound">
<list>
    <value>spring3.rest.bean.Employees</value>
</list>
</property>
</bean>

<bean id="employees" class="org.springframework.web.servlet.view.xml.MarshallingView">
<constructor-arg ref="jaxbMarshaller" />
</bean>

<bean class="org.springframework.web.servlet.view.ContentNegotiatingViewResolver">
<property name="viewResolvers">
    <list>
        <bean     class="org.springframework.web.servlet.view.BeanNameViewResolver" />
        <bean id="viewResolver"     class="org.springframework.web.servlet.view.UrlBasedViewResolver">
            <property name="viewClass"         value="org.springframework.web.servlet.view.JstlView"/>
            <property name="prefix" value="/WEB-INF/jsp/"/>
            <property name="suffix" value=".jsp"/>
        </bean>
    </list>
</property>
</bean>

employees.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org    /TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<table border=1>
<thead><tr>
    <th>FirstName</th>
    <th>LastName</th>
</tr></thead>
<c:forEach var="employee" items="${employees.employees}">
<tr>
    <td>${employee.firstName}</td>
    <td>${employee.lastName}</td>
</tr>
</c:forEach>
</table>


</body>
</html>

EmployeesController.java

package spring3.rest.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import spring3.rest.bean.Employees;

@Controller
@RequestMapping("/employees")
public class EmployeesController {
  @RequestMapping(method=RequestMethod.GET, value="/{id}")
  public ModelAndView getEmployee(@PathVariable("id") String id){
      Employees e = new Employees();
      e.setFirstName("Eugene");
      e.setLastName("Anthony");
      return new ModelAndView("employees", "employees", e);
  }
}

Employees.java

package spring3.rest.bean;

public class Employees {
private String firstName;
private String lastName;

public String getFirstName() {
    return firstName;
}
public void setFirstName(String firstName) {
    this.firstName = firstName;
}
public String getLastName() {
    return lastName;
}
public void setLastName(String lastName) {
    this.lastName = lastName;
}
}

敬请您提供帮助。

谢谢。

最佳回答
问题回答

由此产生的战争档案的名称是什么? 页: 1 <代码><servlet-name> of their web.xml is only a reasonable name formap a request (identated by the <url-pattern>) to a specific servlet, it is not a part of the url. 在你提出请求时,打断。





相关问题
Allow RESTful DELETE method in asp.net mvc?

im currently setting up asp.net to accept DELETE http verb in the application. However, when i send "DELETE /posts/delete/1" i always get a 405 Method not allow error. I tried to take a look at ...

Most appropriate API for URL shortening service

I ve just finished an online service for shortening URLs (in php5 with Zend Framework); you can enter an URL and you get an short URL (like tinyurl and such sites). I m thinking about the API for ...

Use HTTPClient or HttpUrlConnection? [closed]

We re implementing a REST client on JRE 1.4. Seems two good options for a client REST framework are HttpClient and HttpUrlConnection. Is there a reason to use HttpClient over the JRE s ...

Why can t I find the truststore for an SSL handshake?

I m using the Spring RESTTemplate on the client side to make calls to a REST endpoint. The client in this case is a Spring app and Tomcat is the servlet container. I m running into issues making a ...

Which Http redirects status code to use?

friendfeed.com uses 302. bit.ly uses 301. I had decided to use 303. Do they behave differently in terms of support by browsers ?

Three Step Buyonline The RESTful way

We are re-developing our buyonline functionality and we are doing it the RESTful way. The process is a three step one and the customer is asked to enter data at each step. Let s say the three URL s ...

热门标签