Dom4j 使用方法(二)

本文详细介绍了使用Java创建Web应用的过程,并着重讲解了如何使用Spring框架进行配置,包括Servlet、视图解析器和组件扫描等关键部分。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

public class Test02 {
	public static void main(String[] args) {
		System.out.println(formXML02());
		System.out.println();
		System.out.println(formXML03());
		System.out.println();
		System.out.println(formXML04());
	}
	
	public static String formXML01() {
		Document doc = DocumentHelper.createDocument();
		Element tx = doc.addElement("TX");
		tx.addElement("REQUEST_SN").addText("0000000123");
		tx.addElement("CUST_ID").addText("P000568018967#0");
		tx.addElement("USER_ID").addText("WLPT01");
		tx.addElement("PASSWORD").addText("111111");
		tx.addElement("TX_CODE").addText("6W0100");
		tx.addElement("LANGUAGE").addText("CN");
		tx.addElement("TX_INFO")
			.addElement("ACC_NO").addText("31001512200050042645");
		
		return doc.asXML();
	}
	
	public static String formXML02() {
		Document doc = DocumentHelper.createDocument();
		Element webapp = doc.addElement("web-app", "http://java.sun.com/xml/ns/javaee");
		webapp.addNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
		webapp.addNamespace("schemaLocation", "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd");
		webapp.addNamespace("version", "2.5");
		{	
			webapp.addElement("display-name").addText("Spring3MVC");
			
			Element servlet = webapp.addElement("servlet");
			{
				servlet.addElement("servlet-name").addText("spring");
				servlet.addElement("servlet-class").addText("org.springframework.web.servlet.DispatcherServlet");
				servlet.addElement("load-on-startup").addText("1");
			}
			
			Element sm = webapp.addElement("servlet-mapping");
			{
				sm.addElement("servlet-name").addText("spring");
				sm.addElement("url-pattern").addText("*.html");
			}
			
			webapp.addElement("welcome-file-list").addElement("welcome-file").addText("index.jsp");
		}

		return doc.asXML();
	}
	
	public static String formXML03() {
		Document doc = DocumentHelper.createDocument();
		Element beans = doc.addElement("beans", "http://www.springframework.org/schema/beans");
		beans.addNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
		beans.addNamespace("p", "http://www.springframework.org/schema/p");
		beans.addNamespace("context", "http://www.springframework.org/schema/context");
		beans.addNamespace("schemaLocation", "http://www.springframework.org/schema/beans " +
				"http://www.springframework.org/schema/beans/spring-beans-3.0.xsd " +
				"http://www.springframework.org/schema/context " +
				"http://www.springframework.org/schema/context/spring-context-3.0.xsd");
		{	
			beans.addElement("context:component-scan").addAttribute("base-package", "net.spring.controller");
			
			Element bean = beans.addElement("bean");
			bean.addAttribute("id", "viewResolver");
			bean.addAttribute("class", "org.springframework.web.servlet.view.UrlBasedViewResolver");
			{
				Element property = bean.addElement("property");
				{
					property.addAttribute("name", "viewClass");
					property.addAttribute("value", "org.springframework.web.servlet.view.JstlView");
				}
				
				property = bean.addElement("property");
				{
					property.addAttribute("name", "prefix");
					property.addAttribute("value", "/WEB-INF/jsp/");
				}
				
				property = bean.addElement("property");
				{
					property.addAttribute("name", "suffix");
					property.addAttribute("value", ".jsp");
				}
			}			
		}

		return doc.asXML();
	}
	
	public static String formXML04() {
		Document doc = DocumentHelper.createDocument();
		Element fe = doc.addElement("config").addElement("modules")
				.addElement("Fido_Example");
		{
			fe.addElement("active").addText("true");
			fe.addElement("codePool").addText("local");
		}
		
		return doc.asXML();
	}
	
	public static String formXML05() {
		Document doc = DocumentHelper.createDocument();
		Element fe = doc.addElement("config").addElement("modules")
				.addElement("Fido_Example");
//		{
//			fe.addElement("active").addText("true");
//			fe.addElement("codePool").addText("local");
//		}
		
		return doc.asXML();
	}
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值