静态页面发布问题

博客介绍了静态页面发布问题,流程是在后台管理console上,用bean管理freemark的cxf - service.Xml配置文件,访问 /services/* 会初始化。包括创建接口和实现类、建立cxf - service.xml等步骤,还提到使用wsimport工具生成文件,最后建立工具类Constants.java并提及项目遇到的规范问题。

静态页面发布问题

建立在后台管理的console上

 流程:

用bean 管理  freemark的cxf-service.Xml配置文件 

当访问  /services/* 是会被初始化


第一步把接口和接口实现类创建出来

第二步:建立cxf-service.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" xmlns:jaxws="http://cxf.apache.org/jaxws"
	xmlns:jaxrs="http://cxf.apache.org/jaxrs" xmlns:cxf="http://cxf.apache.org/core"
	xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans.xsd
            http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
            http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
            http://cxf.apache.org/core http://cxf.apache.org/schemas/core.xsd">
	<!-- 引入CXF Bean定义如下,早期的版本中使用 -->
	<import resource="classpath:META-INF/cxf/cxf.xml" />
	<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
	<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
	
	<jaxws:server id="publishItem" address="/publishItem" serviceClass="com.rl.ws.service.EbItemServiceWS">
		<jaxws:serviceBean>
			<bean class="com.rl.ws.service.impl.EbItemServiceWSImpl"></bean>
		</jaxws:serviceBean>
	</jaxws:server>
	
	
</beans>

第三部

在web.xml中

<context-param>
		<param-name>contextConfigLocation</param-name>
		<param-value>classpath*:beans.xml,classpath*:cxf-servlet.xml</param-value>
</context-param>

<servlet>
	 <servlet-name>cxf</servlet-name>
	 <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
	 <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
	<servlet-name>cxf</servlet-name>
	<url-pattern>/services/*</url-pattern>
</servlet-mapping>

启动服务器



使用wsimport 工具生产webservice  文件

导入工程

EbItemServiceWSImpl.java

package com.rl.ws.service.impl;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.rl.dao.EbItemDao;
import com.rl.dao.EbSkuDao;
import com.rl.model.EbItem;
import com.rl.util.Constants;
import com.rl.util.FMutil;
import com.rl.ws.service.EbItemServiceWS;

@Service
public class EbItemServiceWSImpl implements EbItemServiceWS {

	/**
	 * 注入商品 和 模板工具类
	 */
	@Autowired
	EbItemDao itemDao;
	@Autowired
	FMutil fm;

	// 密码 和商品id
	public String publishItem(String password, Long itemId) throws Exception {
		String flag = "success";

		if (Constants.ws_pass.equals(password)) {
			EbItem item = itemDao.getProductDetail(itemId);
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("item", item);

			fm.ouputFile("productDetail.ftl", itemId + ".html", map);

		} else {
			flag = "pass_error";
		}

		return flag;
	}

}

EbItemServiceWS.java

package com.rl.ws.service;

import javax.jws.WebService;


@WebService
public interface EbItemServiceWS {
	//传入密码 和 商品id
	public String publishItem(String password, Long itemId) throws Exception;

}

到controller端实现

@Controller
@RequestMapping("/item")
public class EbItemController {
        @Autowired
	EbItemService itemService;

        @RequestMapping("/publishItem.do")
	public void publishItem(Long itemId, PrintWriter out){
		String flag = itemService.publishItem("12345", itemId);
		out.write(flag);
	}
}

Jsp页面

 

写入ajax

function publish(itemId){
       tipShow("#refundLoadDiv");
       var option = {
                url:"${path}/item/publishItem.do",
                type:"post",
                dataType:"text",
                data:{
                    itemId:itemId
                },
                success:function(responseText){
                    if(responseText == "success"){
                        alert("发布成功");
                    }else{
                        alert("密码错误");
                    }
                    tipHide("#refundLoadDiv");
                    
                },
                error:function(){
                    alert("系统错误");
                }
        };
        $.ajax(option);
   }

建立工具类

Constants.java

package com.rl.util;
public interface Constants {
	// 图片服务器的主机路径
	public static final String image_path = "http://localhost:8088/ecps-image/";
        public static final String ws_pass = "12345";
 }

项目中遇到的问题

这样写规范



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值