`
summer_021
  • 浏览: 57951 次
  • 性别: Icon_minigender_1
  • 来自: 上海
最近访客 更多访客>>
社区版块
存档分类
最新评论

Google MapSite

阅读更多
公司要做SEO 研究了一下mapsite
HttpServletResponse response = ServletActionContext.getResponse();
		Document document = DocumentHelper.createDocument();
		
		Element rootElement = null;
		if(this.spider == 0){//百度不需要namespace
			rootElement = document.addElement("urlset");
		} else {//谷歌需要namespace
			rootElement = document.addElement("urlset", "http://www.sitemaps.org/schemas/sitemap/0.9");  
			rootElement.addNamespace("xsi","http://www.w3.org/2001/XMLSchema-instance");  
			rootElement.addAttribute("xsi:schemaLocation","http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd"); 
		}

		for(BnsProfile profile :profiles){
			Element urlElement = rootElement.addElement("url");
			Element locElement = urlElement.addElement("loc");
			Element lastmodElement = urlElement.addElement("lastmod");
			Element changefreqElement = urlElement.addElement("changefreq");
			Element priorityElement = urlElement.addElement("priority");
			locElement.setText("http://www.ushi.cn/p/"+profile.getDomain()+"");
			if(this.spider == 0){//百了度
				lastmodElement.setText((DateFormat.getDateInstance(DateFormat.MEDIUM).format(profile.getLastlogintime())));
			}else if(this.spider == 1){//谷歌
				lastmodElement.setText((DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.format(profile.getLastlogintime())));
			}
			
			changefreqElement.setText("weekly");
			priorityElement.setText(0.5+"");
		}
		response.setContentType("text/xml; charset=utf-8");
		response.setHeader("pragma", "no-cache");
		response.setHeader("cache-control", "no-cache");
		PrintWriter out = response.getWriter();
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding("utf-8");
		XMLWriter xmlWriter = new XMLWriter(out, format);
		xmlWriter.write(document);
		out.flush();
		out.close();
		return Action.NONE;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics