2007-3-27 15:00 bufegar
/**
*SelectServelet.java 澶勭悊欏甸潰榪斿洖鐨勬暟鎹?榪斿洖XML緇橝JAX浣跨敤
*
*/
[java]
package onlinetest.servlet;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class SelectServlet extends HttpServlet {
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
String targetId = request.getParameter("id").toString();
// 鑾峰緱璇鋒眰涓弬鏁頒負id鐨勫?br> String xml_start = "<selects>";
String xml_end = "</selects>";
String xml = "";
if (targetId.equalsIgnoreCase("0")) {
xml = "<select><value>0</value><text>Unbounded</text></select>";
} else if (targetId.equalsIgnoreCase("1")) {
xml = "<select><value>1</value><text>Mana Burn</text></select>";
xml += "<select><value>2</value><text>Death Coil</text></select>";
xml += "<select><value>3</value><text>Unhkly Aura</text></select>";
xml += "<select><value>4</value><text>Unholy Fire</text></select>";
} else if (targetId.equalsIgnoreCase("2")) {
xml = "<select><value>1</value><text>Corpexplode</text></select>";
xml += "<select><value>2</value><text>Raise Dead</text></select>";
xml += "<select><value>3</value><text>Brilliance Aura</text></select>";
xml += "<select><value>4</value><text>Aim Aura</text></select>";
} else {// 濡傛灉鏄?,鍒欒繑鍥炰笅闈㈢殑瀛楃
xml = "<select><value>1</value><text>Rain of Chaos</text></select>";
xml += "<select><value>2</value><text>Finger of Death</text></select>";
xml += "<select><value>3</value><text>Bash</text></select>";
xml += "<select><value>4</value><text>Summon Doom</text></select>";
}
String last_xml = xml_start + xml + xml_end;
response.getWriter().write(last_xml);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);// 瀵逛簬post鐨勮姹傛柟寮忓拰get璇鋒眰鏂瑰紡涓鏍峰鐞?br> }
}
[/java]
2007-3-27 15:02 bufegar
/**
*web.xml 閰嶇疆Servlet,鍙互浣跨敤MyEclipse鍒涘緩Servlet,鑷姩鐢熸垚web.xml
*
*/
[xml]
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="<a target="_blank">[url]http://java.sun.com/xml/ns/j2ee[/url]"</a> xmlns:xsi="<a target="_blank">[url]http://www.w3.org/2001/XMLSchema-instance[/url]"</a> version="2.4" xsi:schemaLocation="<a target="_blank">[url]http://java.sun.com/xml/ns/j2ee[/url]</a> <a target="_blank">[url]http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd[/url]"></a>
<servlet>
<servlet-name>select</servlet-name>
<servlet-class>onlinetest.servlet.SelectServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>select</servlet-name>
<url-pattern>/servlet/select</url-pattern>
</servlet-mapping>
<filter>
<filter-name>characterFilter</filter-name>
<filter-class>filters.SetCharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>characterFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>[/xml]
鍘熸枃鍦板潃:[url]http://my.boolean.cn/read.php?130&part=3[/url]