我介绍一下
1.简单一个小功能
2.没有对数据库进行操作
3.操作的文件时xml,修改数据和插入数据都是对xml文件进行的操作我在做修改时,想吧list的一个对象的属性传回Acion 不知道为什么传不回去
我想在表单提交时传一个参数或多个参数(对象的属性) 到Action 不知道为什么Action获取不了值 大家有什么好的传参方法吗 ?
下边看代码:
Action文件/**
* 读出列表(查询)
*/
public String toList() throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
List infoList = new ArrayList();
File secretFile = new File(filePath);
// 判断是否存在当天xml文件
if (secretFile.exists()) {
// 读出当前xml文件的值
String strxml = "";
BufferedReader reader = new BufferedReader(new FileReader(filePath));
strxml = reader.readLine();
// 如果xml文件不为空
if (strxml != null && !strxml.equals("")) {
infoList = marshallerSecretDomainList(filePath);
//infoList存到了一个request传到index页面
}
} else {
secretFile.createNewFile();
}
return "index";
}/**
* 修改任务
*/
public String toUpdate() throws UnsupportedEncodingException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
// 从页面获取值
String seq = new String(request.getParameter("seq").getBytes(
"ISO8859-1"), "UTF-8");
String path = new String(request.getParameter("path").getBytes(
"ISO8859-1"), "UTF-8");
String date = new String(request.getParameter("date").getBytes(
"ISO8859-1"), "UTF-8");
String time = new String(request.getParameter("time").getBytes(
"ISO8859-1"), "UTF-8");
String level = new String(request.getParameter("level").getBytes(
"ISO8859-1"), "UTF-8");
String guardTarget = new String(request.getParameter("guardTarget")
.getBytes("ISO8859-1"), "UTF-8");
String re = new String(request.getParameter("re").getBytes(
"ISO8859-1"), "UTF-8"); SecretService sec = new SecretService();
sec.setSeq(seq);
sec.setPath(path);
sec.setDate(date);
sec.setTime(time);
sec.setLevel(level);
sec.setGuardTarget(guardTarget);
sec.setRe(re); request.setAttribute("secret", sec);
return "editTask";
}insexj.sp页面我想在表单提交时传一个参数或多个参数(对象的属性) 到Action 不知道为什么Action获取不了值 大家有什么好的传参方法吗 ? <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="ss" uri="/struts-tags" %>
<%@ page import="java.util.*" %>
<%@ page import="com.broadvident.test.*" %><%
List<SecretService> infoList= new ArrayList<SecretService>();
infoList=(List)request.getAttribute("infoList");
%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>特勤任务管理</title>
<link href="css/main.css" rel="stylesheet" type="text/css"><style type="text/css">
<!--
.BTittle{
color:#09468F;
font-family: "黑体";
font-size:18px;
text-decoration: none;
margin-top: 5px;
margin-bottom: 5px;
line-height: 26px;
text-align: center;
}
-->
</style>
<!--判断单选按钮是否选择 -->
<script type="text/javascript" language="javascript">
function checkRadioButton(){
var result=false;
for(var i=0;i<document.myForm.radiobutton.length;i++){
if(document.myForm.radiobutton[i].checked==true){
result=true;
}
}
if(!result){
alert("请选择要修改的项");
}
return result;
}
function fun_getParam(seq,path,date,time,level,guardTarget,re){
window.myForm.action="SecretAction_toUpdate?seq="+seq+"&path="+path+"&date="+date+"&time="+time+"&level="+level+"&guardTarget="+guardTarget+"&re="+re;
for(var i=0;i<document.myForm.radiobutton.length;i++){
document.myForm.radiobutton[i].checked==false;
}
}
</script>
</head><body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="5" colspan="3" align="center" valign="top" bgcolor="#E1F6FF"></td>
</tr>
<tr>
<td width="5" rowspan="2" align="center" valign="top" bgcolor="#E1F6FF"></td>
<td align="center" valign="top" bgcolor="#FFFFFF"><table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="97%" border="0" cellpadding="0" cellspacing="0" class="table01">
<tr>
<td width="5%" align="center"> </td>
<td align="left"><table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="30"><img src="image/01.jpg" width="20" height="25"></td>
<td align="left" ><span class="BTittle">任务管理</span></td>
</tr>
</table>
<table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%" class="font_bule f14px b">特勤任务列表</td>
<td> </td>
</tr>
</table>
<table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<form action="SecretAction_toUpdate?****" name="myForm" method="post" onsubmit="return(checkRadioButton())">
<input type="hidden" name="seq" id="seq">
<table width="98%" border="0" cellpadding="0" cellspacing="0" class="table f12px">
<tr>
<td colspan="6" align="center" background="image/menu01_bg.gif" class="f14px b">
<div align="right">
<input type="button" class="btn" value="写入文件" onclick="location.href='SecretAction_writeFile'">
<input name="Submit" type="button" class="btn" value="新增任务" onClick="location.href='SecretAction_toInsert'">
<input name="Submit2" type="submit" class="btn" value="修改任务" >
<input name="Submit3" type="button" class="btn" value="查看明细" onClick="location.href='taskInfo.jsp'">
</div></td>
</tr>
<tr>
<td width="5%" align="center" background="image/menu01_bg.gif" class="f14px b">选择</td>
<td width="9%" align="center" background="image/menu01_bg.gif" class="f14px b">序号</td>
<td width="48%" align="center" background="image/menu01_bg.gif" class="f14px b">特勤内容</td>
<td width="18%" align="center" background="image/menu01_bg.gif" class="f14px b">日期</td>
<td width="11%" align="center" background="image/menu01_bg.gif" class="f14px b">时间</td>
<td width="9%" align="center" background="image/menu01_bg.gif" class="f14px b">级别</td>
</tr>
<%
if(infoList!=null && infoList.size()>0){
%>
<ss:iterator id="secret" value="#request.infoList" status="status">
<tr>
<td align="center">
<input type="radio" name="radiobutton" value="radiobutton" onclick="fun_getParam('${secret.seq}','${secret.path}','${secret.date}','${secret.time}','${secret.level}','${secret.guardTarget}','${secret.re}');">
</td>
<td align="center">${secret.seq}</td>
<td align="left">${secret.path}</td>
<td align="left"><div align="center">${secret.date}</div></td>
<td align="left"><div align="center">${secret.time}</div></td>
<td align="left">
<div align="center">${secret.level}</div>
</td>
</tr>
</ss:iterator>
<%
}else{
%>
<tr>
<td colspan="6" align="center">您今天还没有任务...</td>
</tr>
<%
}
%>
</table>
</form>
<table width="98%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="f12px"><br><div align="right">首页 上一页 下一页 尾页 总计2
页,当前为 1页 </div></td>
</tr>
</table>
<table width="99%" height="1
0" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="5" rowspan="2" align="center" valign="top" bgcolor="#E1F6FF"></td>
</tr>
<tr>
<td height="5" align="center" valign="top" bgcolor="#E1F6FF"></td>
</tr>
</table>
</body>
</html>
1.简单一个小功能
2.没有对数据库进行操作
3.操作的文件时xml,修改数据和插入数据都是对xml文件进行的操作我在做修改时,想吧list的一个对象的属性传回Acion 不知道为什么传不回去
我想在表单提交时传一个参数或多个参数(对象的属性) 到Action 不知道为什么Action获取不了值 大家有什么好的传参方法吗 ?
下边看代码:
Action文件/**
* 读出列表(查询)
*/
public String toList() throws IOException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
List infoList = new ArrayList();
File secretFile = new File(filePath);
// 判断是否存在当天xml文件
if (secretFile.exists()) {
// 读出当前xml文件的值
String strxml = "";
BufferedReader reader = new BufferedReader(new FileReader(filePath));
strxml = reader.readLine();
// 如果xml文件不为空
if (strxml != null && !strxml.equals("")) {
infoList = marshallerSecretDomainList(filePath);
//infoList存到了一个request传到index页面
}
} else {
secretFile.createNewFile();
}
return "index";
}/**
* 修改任务
*/
public String toUpdate() throws UnsupportedEncodingException {
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
// 从页面获取值
String seq = new String(request.getParameter("seq").getBytes(
"ISO8859-1"), "UTF-8");
String path = new String(request.getParameter("path").getBytes(
"ISO8859-1"), "UTF-8");
String date = new String(request.getParameter("date").getBytes(
"ISO8859-1"), "UTF-8");
String time = new String(request.getParameter("time").getBytes(
"ISO8859-1"), "UTF-8");
String level = new String(request.getParameter("level").getBytes(
"ISO8859-1"), "UTF-8");
String guardTarget = new String(request.getParameter("guardTarget")
.getBytes("ISO8859-1"), "UTF-8");
String re = new String(request.getParameter("re").getBytes(
"ISO8859-1"), "UTF-8"); SecretService sec = new SecretService();
sec.setSeq(seq);
sec.setPath(path);
sec.setDate(date);
sec.setTime(time);
sec.setLevel(level);
sec.setGuardTarget(guardTarget);
sec.setRe(re); request.setAttribute("secret", sec);
return "editTask";
}insexj.sp页面我想在表单提交时传一个参数或多个参数(对象的属性) 到Action 不知道为什么Action获取不了值 大家有什么好的传参方法吗 ? <%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="ss" uri="/struts-tags" %>
<%@ page import="java.util.*" %>
<%@ page import="com.broadvident.test.*" %><%
List<SecretService> infoList= new ArrayList<SecretService>();
infoList=(List)request.getAttribute("infoList");
%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>特勤任务管理</title>
<link href="css/main.css" rel="stylesheet" type="text/css"><style type="text/css">
<!--
.BTittle{
color:#09468F;
font-family: "黑体";
font-size:18px;
text-decoration: none;
margin-top: 5px;
margin-bottom: 5px;
line-height: 26px;
text-align: center;
}
-->
</style>
<!--判断单选按钮是否选择 -->
<script type="text/javascript" language="javascript">
function checkRadioButton(){
var result=false;
for(var i=0;i<document.myForm.radiobutton.length;i++){
if(document.myForm.radiobutton[i].checked==true){
result=true;
}
}
if(!result){
alert("请选择要修改的项");
}
return result;
}
function fun_getParam(seq,path,date,time,level,guardTarget,re){
window.myForm.action="SecretAction_toUpdate?seq="+seq+"&path="+path+"&date="+date+"&time="+time+"&level="+level+"&guardTarget="+guardTarget+"&re="+re;
for(var i=0;i<document.myForm.radiobutton.length;i++){
document.myForm.radiobutton[i].checked==false;
}
}
</script>
</head><body>
<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="5" colspan="3" align="center" valign="top" bgcolor="#E1F6FF"></td>
</tr>
<tr>
<td width="5" rowspan="2" align="center" valign="top" bgcolor="#E1F6FF"></td>
<td align="center" valign="top" bgcolor="#FFFFFF"><table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="97%" border="0" cellpadding="0" cellspacing="0" class="table01">
<tr>
<td width="5%" align="center"> </td>
<td align="left"><table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="98%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="30"><img src="image/01.jpg" width="20" height="25"></td>
<td align="left" ><span class="BTittle">任务管理</span></td>
</tr>
</table>
<table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<table width="80%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="20%" class="font_bule f14px b">特勤任务列表</td>
<td> </td>
</tr>
</table>
<table width="99%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table>
<form action="SecretAction_toUpdate?****" name="myForm" method="post" onsubmit="return(checkRadioButton())">
<input type="hidden" name="seq" id="seq">
<table width="98%" border="0" cellpadding="0" cellspacing="0" class="table f12px">
<tr>
<td colspan="6" align="center" background="image/menu01_bg.gif" class="f14px b">
<div align="right">
<input type="button" class="btn" value="写入文件" onclick="location.href='SecretAction_writeFile'">
<input name="Submit" type="button" class="btn" value="新增任务" onClick="location.href='SecretAction_toInsert'">
<input name="Submit2" type="submit" class="btn" value="修改任务" >
<input name="Submit3" type="button" class="btn" value="查看明细" onClick="location.href='taskInfo.jsp'">
</div></td>
</tr>
<tr>
<td width="5%" align="center" background="image/menu01_bg.gif" class="f14px b">选择</td>
<td width="9%" align="center" background="image/menu01_bg.gif" class="f14px b">序号</td>
<td width="48%" align="center" background="image/menu01_bg.gif" class="f14px b">特勤内容</td>
<td width="18%" align="center" background="image/menu01_bg.gif" class="f14px b">日期</td>
<td width="11%" align="center" background="image/menu01_bg.gif" class="f14px b">时间</td>
<td width="9%" align="center" background="image/menu01_bg.gif" class="f14px b">级别</td>
</tr>
<%
if(infoList!=null && infoList.size()>0){
%>
<ss:iterator id="secret" value="#request.infoList" status="status">
<tr>
<td align="center">
<input type="radio" name="radiobutton" value="radiobutton" onclick="fun_getParam('${secret.seq}','${secret.path}','${secret.date}','${secret.time}','${secret.level}','${secret.guardTarget}','${secret.re}');">
</td>
<td align="center">${secret.seq}</td>
<td align="left">${secret.path}</td>
<td align="left"><div align="center">${secret.date}</div></td>
<td align="left"><div align="center">${secret.time}</div></td>
<td align="left">
<div align="center">${secret.level}</div>
</td>
</tr>
</ss:iterator>
<%
}else{
%>
<tr>
<td colspan="6" align="center">您今天还没有任务...</td>
</tr>
<%
}
%>
</table>
</form>
<table width="98%" height="10" border="0" cellpadding="0" cellspacing="0">
<tr>
<td class="f12px"><br><div align="right">首页 上一页 下一页 尾页 总计2
页,当前为 1页 </div></td>
</tr>
</table>
<table width="99%" height="1
0" border="0" cellpadding="0" cellspacing="0">
<tr>
<td></td>
</tr>
</table></td>
</tr>
</table></td>
<td width="5" rowspan="2" align="center" valign="top" bgcolor="#E1F6FF"></td>
</tr>
<tr>
<td height="5" align="center" valign="top" bgcolor="#E1F6FF"></td>
</tr>
</table>
</body>
</html>
在Action中定义成员变量seq path date time level等等,配好相应的get/set方法就可以传参数了。
如果Action中已经这么做过了,那么可能是页面中的JS做得不对。
但是会有错 单击一个radiobutton的时候回调用这个函数
但是如果你选中之后 点击修改按钮 在后退回这个页面 在点击修改 就会报错了
这个函数只有在点击单选按钮以后才会赋值 Action才可以被获取
所以我不想用这个方法了
我想直接在form里传过去 或者吧选中的那一条的索引值传过去
不知道你听明白没
这个方法是可以的 就是用bug 我不想用这个 我想直接在form那转过去 不用js
这两个会不会有冲突。建议你把旧的和新修改的命名不一样
你看看上边页面的form那得代码 你说我在提交时把 seq 属性传到Action form那提交时该怎么写呢?
不会的 那个hidden 现在写不写都一样 我举个例子 就说传seq吧 你说提交的时候该怎么写呢?action="SecretAction_toUpdate?seq=????" 你说这个参数该怎么传呢 如果直接写${secrect.seq} 是传不过去的
你说value的值 该是多少呢? ${secrect.seq}???
用<s:form> 难道就能传值了吗 ?
<input type="hidden" name="seq" id="seq" value="${secrect.seq}">