欏圭洰緇撴瀯鍥撅細

index.jsp:
<%@聽page聽language="java"聽contentType="text/html;聽charset=utf-8"%>
<html>
聽聽<head>
聽聽聽聽<title>My聽JSP聽'index.jsp'聽starting聽page</title>
聽聽聽聽<meta聽http-equiv="Content-Type"聽content="text/html;聽charset=utf-8">
聽聽聽聽<SCRIPT聽type="text/javascript">
聽聽聽聽聽聽聽聽var聽req;
聽聽聽聽聽聽聽聽window.onload=function(){
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽function聽Change_Select()
聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽var聽zhi=document.getElementById('hero').value;
聽聽聽聽聽聽聽聽聽聽聽聽var聽url="select?id="+escape(zhi);
聽聽聽聽聽聽聽聽聽聽聽聽if(window.XMLHttpRequest)
聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽req=new聽XMLHttpRequest();
聽聽聽聽聽聽聽聽聽聽聽聽}else聽if(window.ActiveXObject)
聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽req=new聽ActiveXObject("Microsoft.XMLHTTP");
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽if(req)
聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽req.open("GET",url,true);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽req.onreadystatechange=callback;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽req.send(null);
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽function聽callback()
聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽if(req.readyState聽==聽4)
聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽if(req.status聽==聽200)
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽parseMessage();
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}else{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽alert("Not聽able聽to聽retrieve聽description"+req.statusText);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽function聽parseMessage()
聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽var聽xmlDoc=req.responseXML.documentElement;
聽聽聽聽聽聽聽聽聽聽聽聽var聽xSel=xmlDoc.getElementsByTagName('select');
聽聽聽聽聽聽聽聽聽聽聽聽var聽select_root=document.getElementById('skill');
聽聽聽聽聽聽聽聽聽聽聽聽select_root.options.length=0;
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽for(var聽i=0;i<xSel.length;i++)
聽聽聽聽聽聽聽聽聽聽聽聽{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽var聽xValue=xSel[i].childNodes[0].firstChild.nodeValue;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽var聽xText=xSel[i].childNodes[1].firstChild.nodeValue;
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽var聽option=new聽Option(xText,xValue);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽try{
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽select_root.add(option);
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}catch(e){
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽}
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽聽聽聽聽
聽聽聽聽聽聽聽聽}
聽聽聽聽</SCRIPT>
聽聽</head>
聽聽
聽聽<body>
聽聽聽聽<div聽align="center">
聽聽聽聽聽聽聽聽<form聽name="form1"聽method="post"聽action="">
聽聽聽聽聽聽聽聽聽聽聽聽<TABLE聽width="70%"聽boder="0"聽cellspacing="0">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<TR>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<TD聽align="center">Double聽Select聽Box</TD>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</TR>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<TR>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<TD>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<SELECT聽name="hero"聽id="hero"聽onChange="Change_Select()">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<OPTION聽value="0">Unbounded</OPTION>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<OPTION聽value="1">D.K.</OPTION>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<OPTION聽value="2">NEC.</OPTION>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<OPTION聽value="3">BOSS</OPTION>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</SELECT>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<SELECT聽name="skill"聽id="skill">
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<OPTION聽value="0">Unbounded</OPTION>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</SELECT>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</TD>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽</TR>
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽<TR><td> </td></TR>
聽聽聽聽聽聽聽聽聽聽聽聽</TABLE>
聽聽聽聽聽聽聽聽</form>
聽聽聽聽</div>
聽聽</body>
</html>
SelectServlet.java:
package聽com;
import聽java.io.IOException;
import聽java.io.PrintWriter;
import聽javax.servlet.ServletException;
import聽javax.servlet.http.HttpServlet;
import聽javax.servlet.http.HttpServletRequest;
import聽javax.servlet.http.HttpServletResponse;
public聽class聽SelectServlet聽extends聽HttpServlet聽{
聽聽聽聽/**
聽聽聽聽聽*聽Constructor聽of聽the聽object.
聽聽聽聽聽*/
聽聽聽聽public聽SelectServlet()聽{
聽聽聽聽聽聽聽聽super();
聽聽聽聽}
聽聽聽聽/**
聽聽聽聽聽*聽Destruction聽of聽the聽servlet.聽<br>
聽聽聽聽聽*/
聽聽聽聽public聽void聽destroy()聽{
聽聽聽聽聽聽聽聽super.destroy();聽//聽Just聽puts聽"destroy"聽string聽in聽log
聽聽聽聽聽聽聽聽//聽Put聽your聽code聽here
聽聽聽聽}
聽聽聽聽/**
聽聽聽聽聽*聽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();
聽聽聽聽聽聽聽聽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>Unholy聽Aura</text></select>";
聽聽聽聽聽聽聽聽聽聽聽聽xml聽+="<select><value>4</value><text>Unholy聽Fire</text></select>";
聽聽聽聽聽聽聽聽}else聽if(targetId.equalsIgnoreCase("2")){
聽聽聽聽聽聽聽聽聽聽聽聽xml="<select><value>1</value><text>Corprxplode</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);
聽聽聽聽}
聽聽聽聽/**
聽聽聽聽聽*聽Initialization聽of聽the聽servlet.聽<br>
聽聽聽聽聽*
聽聽聽聽聽*聽@throws聽ServletException聽if聽an聽error聽occure
聽聽聽聽聽*/
聽聽聽聽public聽void聽init()聽throws聽ServletException聽{
聽聽聽聽聽聽聽聽//聽Put聽your聽code聽here
聽聽聽聽}
}
web.xml:
<?xml聽version="1.0"聽encoding="UTF-8"?>
<web-app聽version="2.4"聽
聽聽聽聽xmlns="http://java.sun.com/xml/ns/j2ee"聽
聽聽聽聽xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"聽
聽聽聽聽xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee聽
聽聽聽聽http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
聽聽<servlet>
聽聽聽聽<servlet-name>SelectServlet</servlet-name>
聽聽聽聽<servlet-class>com.SelectServlet</servlet-class>
聽聽</servlet>
聽聽<servlet-mapping>
聽聽聽聽<servlet-name>SelectServlet</servlet-name>
聽聽聽聽<url-pattern>/select</url-pattern>
聽聽</servlet-mapping>
聽聽聽聽
聽聽聽聽<welcome-file-list>
聽聽聽聽聽聽聽聽<welcome-file>index.jsp</welcome-file>
聽聽聽聽</welcome-file-list>
</web-app>
榪愯緇撴灉鍥撅細


]]>