通过webservice发布静态页面
来源:互联网 发布:机器人技术基础知乎 编辑:程序博客网 时间:2024/06/06 06:59
要想通过webservice发布静态化页面也就是freemaker 首先你要有一个模板页面其次你得写一个服务端实现类和接口
在你要生成的目录下打开cmd命令窗口 输入wsdl2java -d. -p 包名 发布的网址(例如http://localhost:8080/项目名/service)
public class EbWSItemServiceImpl implements EbWSItemService {@Autowiredprivate IEbItemDao itemDao;public String publishItem(Long itemId, String password) throws Exception {if(StringUtils.equals(pass, password)){EbItem item = itemDao.findItemDetailById(itemId); Map<String, Object> map = new HashMap<String, Object>(); map.put("item", item); FMutil fMutil = new FMutil(); fMutil.ouputFile("productDetail.ftl", item.getItemId()+".html", map);return "success";}else{return "password error";}}}
这是我的服务端实现类其中的FMutil是一个生成静态化页面的类
public class FMutil {/** * * @param ftlName:模板名 * @param fileName:生成的html名字 * @param map 数据库中的数据 * @throws Exception */public void ouputFile(String ftlName, String fileName, Map<String, Object> map) throws Exception{//创建fm的配置Configuration config = new Configuration();//指定默认编码格式config.setDefaultEncoding("UTF-8");//设置模板的包路径config.setClassForTemplateLoading(this.getClass(), "/com/cb/ecps/ftl");//获得包的模板Template template = config.getTemplate(ftlName);//指定文件输出的路径String path = "D:/JAVA_EE/workspace/ecps-parent/ecps-protal/src/main/webapp/static";//定义输出流,注意的必须指定编码Writer writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(new File(path+"/"+fileName)),"UTF-8"));//生成模板template.process(map, writer);}}通过这个类指定生成地址 字符编码 就可以生成相应的代码 但是我们要在项目里使用它远远没有这么简单
接下来我们需要将它发布到服务器上 要想发布到服务器上需要如下配置
cxf-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" 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" /><!-- address:http://localhost:8080/ecps-portal/[url-partten]/address如果不加/ 页面则取不到相应路径 --><jaxws:server id="publishItem" address="/publishItem" serviceClass="com.cb.ecps.ws.service.EbWSItemService"><jaxws:serviceBean><bean class="com.cb.ecps.ws.service.impl.EbWSItemServiceImpl"></bean></jaxws:serviceBean></jaxws:server> </beans>web.xml
<!--发布webservice 一旦访问service下的类服务器就将该webservice发布出去--><servlet><servlet-name>cxf</servlet-name><servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class></servlet><servlet-mapping><servlet-name>cxf</servlet-name><url-pattern>/service/*</url-pattern></servlet-mapping>
在你要生成的目录下打开cmd命令窗口 输入wsdl2java -d. -p 包名 发布的网址(例如http://localhost:8080/项目名/service)
这样就能生成客户端代码
阅读全文
0 0
- 通过webservice发布静态页面
- 通过新闻发布系统学习页面静态化
- 静态页面发布问题
- 【WebService】通过CXF发布WebService第一例
- 【WebService】通过CXF发布WebService第一例
- .net发布静态页面代码
- 用github发布静态页面
- 通过Jsr181进行WebService服务发布
- OSGI通过CXF发布WebService第一例
- 通过CXF发布WebService第一例
- CXF整合Spring通过tomcat发布webservice
- 通过Main方法(Endpoint)发布webService服务器
- C#通过动态页面生成静态页面
- .net发布静态页面滚动条
- FreeCMS视频教程 远程发布静态页面
- 通过Web页面自动发布客户端软件
- 将本地的静态页面发布,没服务器怎么发布?
- 通过模板生成静态页面示例
- 百度地图之定位
- jsp九大内置对象小结
- 利用Python处理Excel数据
- 337C
- 通过Anaconda安装Python
- 通过webservice发布静态页面
- B
- XAMPP里tomcat启动报错:Make sure you have Java JDK or JRE installed and the required ports are free
- 开始我的图像处理学习
- Leetcode 89: Java移位运算符作指数的开方
- 大整数乘法
- 蛇形矩阵
- 最大公因数-欧几里得算法
- SQL语句