根据Ajax 一组选择按钮。第二个的内容根据第一个的选择而即时改变,使用Ajax与服务器异步交互数据。
技术最好是用struts1 加 ajax实现。希望懂的朋友写具体点。比如把action 里的实现方法写明。 表嘛 就用 部门dept 和员工emp 。感激不尽!!!
技术最好是用struts1 加 ajax实现。希望懂的朋友写具体点。比如把action 里的实现方法写明。 表嘛 就用 部门dept 和员工emp 。感激不尽!!!
解决方案 »
- struts2的validation.xml里解析正则表达式的问题
- 原理
- Hibernate测试例子出NoClassDefFoundError错误
- 跪求jbuilder的插件--Productivity Pro
- 救命啊,各位兄弟,关于验证码的怪问题!
- 请问用javamail如何转发给多个人?(普通发送已实现了)
- SQL SERVER 2000的触发器里没有select吗?
- 一般在读写文件时都是对服务器上的文本文件进行读写,比如用文件形式做的留言簿。我现在急需实现读写客户端自己机器上的文本文件,怎么能
- 我忘记了语法,一个简单的问题希望各位帮着解决一下。急!!!
- 哪里有支持断点续传的JBuilder 5 正式版下载?
- tomcate 启动问题
- 提示需要安装插件
只要你理解了Ajax,就没有问题
写代码说明实在太费时间,你可以Google一下
额 只要写action的两个方法 和 jsp页面上的ajax 就行了, 就耽误10分钟的时间。
ajax 理解不了啊,我都纠结这个动态下拉列表两天了,没点头绪··
红色的DIV 的ID 很重要,在JS里用到 main.jsp<td width="18%">Industry:</td>
<td class="mid_tab1_td"><logic:present name="industrydata" scope="session">
<logic:notEmpty name="industrydata" scope="session">
<select name="industry" id="industry" style="width:100%" onchange="depart(this.value)">
<option value=""> </option>
<logic:iterate id="industry" name="industrydata" scope="session">
<option value="<bean:write name="industry" property="sjzdid"/>"><bean:write name="industry" property="sjzdname"/></option>
</logic:iterate>
</select>
</logic:notEmpty>
<logic:empty name="industrydata" scope="session">
<logic:redirect page="/page/login.jsp"></logic:redirect>
</logic:empty>
</logic:present>
<logic:notPresent name="industrydata" scope="session">
<logic:redirect page="/page/login.jsp"></logic:redirect>
</logic:notPresent></td>
<td> </td>
</tr>
<tr>
<td width="18%">Department:</td>
<td class="mid_tab1_td">
<div id="departinfo"> <select name="department" id="department" style="width:100%">
<option value=""> </option>
</select><div>进入main.js
var xmlHttpRequest;
function createXMLHttpRequest(){
if(window.ActiveXObject){
xmlHttpRequest = new ActiveXObject("Microsoft.XMLHTTP");
}else{
xmlHttpRequest = new XMLHttpRequest();
}
}
function depart(industryid){
if(industryid=="")
{
return;
}
var url = "depart.do?method=selectDepartByIndustry&industryid="+industryid;
createXMLHttpRequest();
xmlHttpRequest.open("post", url);
xmlHttpRequest.onreadystatechange = callback;
xmlHttpRequest.send(null);
}
function callback(){
if(xmlHttpRequest.readyState == 4){
if(xmlHttpRequest.status == 200){
departinfo.innerHTML = xmlHttpRequest.responseText;
}
}
}进入action :
package com.hhs.action;import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;import com.hhs.bean.Department;
import com.hhs.service.DeaprtmentServiceImp;public class DepartmentAction extends DispatchAction{
/**
* 根据 行业异步查询部门信息
*/
public ActionForward selectDepartByIndustry(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) throws Exception {
DeaprtmentServiceImp dsp=new DeaprtmentServiceImp();
String industryid=request.getParameter("industryid").trim();
String condition=" where industryid ="+industryid;
List<Department> departmentdata=dsp.SelectDepartmentByCondition(condition);
if(departmentdata!=null)
{
request.setAttribute("departmentdata", departmentdata);
return mapping.findForward("departajax");
}
return mapping.findForward("fail");
}
}
AJAX回调页面:departajax.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<base href="<%=basePath%>">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Department AJAX</title>
</head>
<body>
<logic:present name="departmentdata" scope="request">
<logic:notEmpty name="departmentdata" scope="request">
<select name="department" id="department" style="width:100%">
<option value=""> </option>
<logic:iterate id="department" name="departmentdata" scope="request">
<option value="<bean:write name="department" property="departmentid"/>"><bean:write name="department" property="departmentname"/></option>
</logic:iterate>
</select>
</logic:notEmpty>
<logic:empty name="departmentdata" scope="request">
<select name="department" id="department" style="width:100%">
<option value=""> </option>
</select>
</logic:empty>
</logic:present>
<logic:notPresent name="departmentdata" scope="request">
<logic:redirect page="/page/login.jsp"></logic:redirect>
</logic:notPresent>
</body>
</html>