欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Need Help! Issues in resteasy & spring

程序员文章站 2022-07-16 22:27:13
...
    FYI: Just using resteasy to access the service layer, which returns xml, then using xslt to translate it for view. But... issues below
    If you can fix it, pls let me known kindly. Regards!


Need Help! Issues in resteasy & spring
            
    
    博客分类: springJuniorresteasy springresteasy 


    web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
	<display-name>Archetype Created Web Application</display-name>

	<context-param>
		<param-name>resteasy.scan</param-name>
		<param-value>true</param-value>
	</context-param>
	<!--  
	<context-param>
		<param-name>resteasy.resources</param-name>
		<param-value>com.eric.bms.service.BookService</param-value>
	</context-param>
	-->
	<context-param>
		<param-name>resteasy.servlet.mapping.prefix</param-name>
		<param-value>/resource</param-value>
	</context-param>

	<listener>
		<listener-class>
			org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
		</listener-class>
	</listener>

	<listener>
		<listener-class>
			org.springframework.web.context.ContextLoaderListener
		</listener-class>
	</listener>

	<servlet>
		<servlet-name>Resteasy</servlet-name>
		<servlet-class>
			org.springframework.web.servlet.DispatcherServlet
		</servlet-class>
		<init-param>
			<param-name>ContextConfigLocation</param-name>
			<param-value>classpath:applicationContext.xml</param-value>
		</init-param>
	</servlet>
	<servlet-mapping>
		<servlet-name>Resteasy</servlet-name>
		<url-pattern>/resource/*</url-pattern>
	</servlet-mapping>
</web-app>


    Bean in applicationContext.xml

	<bean id="bookDao" class="com.eric.bms.dao.impl.BookDaoImpl" autowire="byName"/>
	<bean id="bookService" class="com.eric.bms.service.impl.BookServiceImpl" autowire="byName"/>

    The test page
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!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>Show all the books here</title>
<%String path = request.getContextPath(); %>
<script src="<%=path %>/js/book.js" type="text/javascript"></script>
</head>
<body onload='display("<%=path %>/resource/bs/list", "<%=path %>/xsl/bsummary.xsl", "books")'>
<div id="books" align="center"></div>
</body>
</html>

    BookService
@Path("bs")
public interface BookService {

	@GET
	@Produces(MediaType.APPLICATION_XML)
	@Path("/list/")
	BookSummary list();
	
}

    BookServiceImpl
public class BookServiceImpl implements BookService {
	
	private BookDao bookDao;

	public BookSummary list() {
		BookSummary summary = new BookSummary();
		List<Book> list = bookDao.getAll();
		for(Book book : list) {
			summary.getList().add(book);
		}
		return summary;
	}

}
相关标签: spring resteasy

上一篇: RESTEasy 简单实例

下一篇: forge alpha4