关于STRUTS的radio的一个问题 搜索一下 下拉列表 联动问题 答案很多 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 整个程序如下:index.jsp文件<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %><%@ page contentType="text/html; charset=GBK" %><%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %><%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %><%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %><%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%><c:choose> <c:when test="${requestScope.collection==null}"> <jsp:useBean id="jspbean" class="mypackage.DBbean" scope="page"/> <c:set var="bean" value="${jspbean.collection}"/> </c:when> <c:otherwise> <c:set var="bean" value="${requestScope.collection}"/> </c:otherwise></c:choose><html:html locale="true"><head><title>这是一个实验!</title><html:base/></head><body bgcolor="#ffffff"><html:form action="myform.do" method="post" name="ceshiForm" type="mypackage.CeshiForm"><html:radio value="A" property="tableBean.radioAB" onclick="ceshiForm.submit()"/>A<html:radio value="B" property="tableBean.radioAB" onclick="ceshiForm.submit()"/>B<br><html:select property="tableBean.sel"> <html:options collection="bean" labelProperty="name" property="id"/></html:select></html:form></body></html:html>-------------------------------------------------Action文件package mypackage;import mypackage.*;import org.apache.struts.action.*;import javax.servlet.http.*;import java.util.*;public class CeshiAction extends Action { public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) { CeshiForm ceshiForm = (CeshiForm) actionForm; DBbean bean=new DBbean(); Collection coll=bean.getCollection(ceshiForm.getTableBean().getRadioAB()); httpServletRequest.setAttribute("collection",coll); return actionMapping.findForward("success"); }}--------------------------------------------------Form文件package mypackage;import mypackage.*;import org.apache.struts.action.*;import javax.servlet.http.*;public class CeshiForm extends ActionForm { TableBean tableBean=new TableBean(); public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) { ActionErrors errors=new ActionErrors(); return errors; } public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) { this.tableBean=new TableBean(); } public TableBean getTableBean() { return tableBean; } public void setTableBean(TableBean tableBean) { this.tableBean = tableBean; }}---------------------------------------------------连接数据库,封装业务逻辑的beanpackage mypackage;import java.sql.*;import java.io.*;import java.util.*;import mypackage.*;public class DBbean { private Connection conn; public DBbean() { try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); conn=DriverManager.getConnection("jdbc:odbc:jspdev","sa",""); } catch(Exception e){ e.printStackTrace(); } } public Collection getCollection(){ return this.getCollection("A"); } public Collection getCollection(String tableName){ Collection collection=new ArrayList(); try{ Statement stmt=conn.createStatement(); ResultSet rs=stmt.executeQuery("select * from "+tableName); while(rs.next()){ TableBean temp=new TableBean(); temp.setName(rs.getString(1)); temp.setId(rs.getString(2)); collection.add(temp); } rs.close(); stmt.close(); } catch(Exception e){ e.printStackTrace(); } return collection; }}------------------------------------------存储表中的数据的beanpackage mypackage;public class TableBean { private String name; private String id; private String radioAB; private String sel; public String getRadioAB() { return radioAB; } public void setRadioAB(String radioAB) { this.radioAB = radioAB; } public String getSel() { return sel; } public void setSel(String sel) { this.sel = sel; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; }}-------------------------------------------struts-config.xml<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd"><struts-config> <form-beans> <form-bean name="ceshiForm" type="mypackage.CeshiForm" /> </form-beans> <action-mappings> <action name="ceshiForm" type="mypackage.CeshiAction" validate="true" input="/index.jsp" scope="request" path="/myform"> <forward name="success" path="/index.jsp"/> </action> </action-mappings></struts-config>---------------------------------------------数据库use jspdevgocreate table A(id varchar(10), name varchar(10),)create table B(id varchar(10), name varchar(10),)//请自己添加数据配置jspdev的odbc数据源,并创建数据库jspdev----------------------------------------------程序用jb9完成,struts1.0,jstl都是jb9自带的 struts标签HASHMAP取值问题求教 怎么样设置只能从登录页面登录 jsp利用whios进行域名查询(在线等,给分!) jdbc sql server 问题???? jsp现实计数器问题 Servlet实现文件上传,如何获得form中非文件对象的值???(具体见内) 数据和页面格式 JSP上传组件?????????????? JSP问号? java中FileOutputStream和FileWriter的区别. 如何将Servlet中查到的数据返回给JSP页面,JSP将该数据显示出来 参数的传递问题
index.jsp文件
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>
<c:choose>
<c:when test="${requestScope.collection==null}">
<jsp:useBean id="jspbean" class="mypackage.DBbean" scope="page"/>
<c:set var="bean" value="${jspbean.collection}"/>
</c:when>
<c:otherwise>
<c:set var="bean" value="${requestScope.collection}"/>
</c:otherwise>
</c:choose>
<html:html locale="true">
<head>
<title>
这是一个实验!
</title>
<html:base/>
</head>
<body bgcolor="#ffffff">
<html:form action="myform.do" method="post" name="ceshiForm" type="mypackage.CeshiForm">
<html:radio value="A" property="tableBean.radioAB" onclick="ceshiForm.submit()"/>A
<html:radio value="B" property="tableBean.radioAB" onclick="ceshiForm.submit()"/>B
<br>
<html:select property="tableBean.sel">
<html:options collection="bean" labelProperty="name" property="id"/>
</html:select>
</html:form>
</body>
</html:html>
-------------------------------------------------
Action文件
package mypackage;
import mypackage.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.*;
public class CeshiAction extends Action {
public ActionForward perform(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) {
CeshiForm ceshiForm = (CeshiForm) actionForm;
DBbean bean=new DBbean();
Collection coll=bean.getCollection(ceshiForm.getTableBean().getRadioAB());
httpServletRequest.setAttribute("collection",coll);
return actionMapping.findForward("success");
}
}
--------------------------------------------------
Form文件
package mypackage;import mypackage.*;
import org.apache.struts.action.*;
import javax.servlet.http.*;public class CeshiForm extends ActionForm {
TableBean tableBean=new TableBean(); public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
ActionErrors errors=new ActionErrors();
return errors;
}
public void reset(ActionMapping actionMapping, HttpServletRequest httpServletRequest) {
this.tableBean=new TableBean();
}
public TableBean getTableBean() {
return tableBean;
}
public void setTableBean(TableBean tableBean) {
this.tableBean = tableBean;
}
}
---------------------------------------------------
连接数据库,封装业务逻辑的bean
package mypackage;
import java.sql.*;
import java.io.*;
import java.util.*;
import mypackage.*;
public class DBbean {
private Connection conn;
public DBbean() {
try{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
conn=DriverManager.getConnection("jdbc:odbc:jspdev","sa","");
}
catch(Exception e){
e.printStackTrace();
}
}
public Collection getCollection(){
return this.getCollection("A");
}
public Collection getCollection(String tableName){
Collection collection=new ArrayList();
try{
Statement stmt=conn.createStatement();
ResultSet rs=stmt.executeQuery("select * from "+tableName);
while(rs.next()){
TableBean temp=new TableBean();
temp.setName(rs.getString(1));
temp.setId(rs.getString(2));
collection.add(temp);
}
rs.close();
stmt.close();
}
catch(Exception e){
e.printStackTrace();
} return collection;
}
}
------------------------------------------
存储表中的数据的bean
package mypackage;public class TableBean {
private String name;
private String id;
private String radioAB;
private String sel;
public String getRadioAB() {
return radioAB;
}
public void setRadioAB(String radioAB) {
this.radioAB = radioAB;
}
public String getSel() {
return sel;
}
public void setSel(String sel) {
this.sel = sel;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
}
-------------------------------------------
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
<struts-config>
<form-beans>
<form-bean name="ceshiForm" type="mypackage.CeshiForm" />
</form-beans>
<action-mappings>
<action name="ceshiForm" type="mypackage.CeshiAction" validate="true" input="/index.jsp" scope="request" path="/myform">
<forward name="success" path="/index.jsp"/>
</action>
</action-mappings>
</struts-config>
---------------------------------------------
数据库
use jspdev
go
create table A
(id varchar(10),
name varchar(10),
)
create table B
(id varchar(10),
name varchar(10),
)
//请自己添加数据配置jspdev的odbc数据源,并创建数据库jspdev
----------------------------------------------
程序用jb9完成,struts1.0,jstl都是jb9自带的