jsp form表单提交。新手求解,该怎么处理
jsp form表单提交。。新手求解
在jsp页面,无用代码我就不写了,
jsp 里面写的一个java doUpload方法
<% Ta060w sy = new Ta060w();
if (sy.handleIs("upload", pageContext)) {
String re= sy.doUpload(pageContext,"2");
Href hr = new Href("/jk/tactics/ta060w.jsp");
if("-2".equals(re) || "-1".equals(re)){
WebApp.redirect(pageContext, hr.toString(),"数据格式错误,导入不成功");
}else{
WebApp.redirect(pageContext, hr.toString(),"数据导入成功");
}
return;
}
%>
页面标记写了一个form表单:
<form name="form1" method="post" action="ta060w.jsp?handleType=upload" enctype="multipart/form-data">
<td colspan="2" align="center">
<input type="button" value="导 入" onclick="aa()">
<input type="reset" value="取 消"/>
</td>
</form>
在页面的js里面写的脚本,:
<script type="text/javascript">
function aa(){
obj = document.form1.reference;
var user = "<%=user_id%>";
var array = obj.value.split(".");
if(array[array.length-1]=="xlsx"){
toAjax(user);
}else{
alert("导入文件的后缀名必须是xlsx");
document.form1.reset();
}
}
function toAjax(user_id){
xmlHttp = createXMLHttpRequest();
xmlHttp.onreadystatechange = showDetailName;
xmlHttp.open("POST","/jk/CLLock?user_id="+user_id,"true");
xmlHttp.send(null);
}
function showDetailName(){
if(getCurrState(xmlHttp)==200){
var jsonList1=eval("("+xmlHttp.responseText+")");
if(jsonList1.length>0) {
document.form1.submit();
}else{
alert("由 "+jsonList1[2]["user_id"]+" 处理中...");
}
}
}
function createXMLHttpRequest(){
var xmlHttp;
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
function getCurrState(xmlHttp){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
return 200;
}else{
return xmlHttp.status;
}
}else{
xmlHttp.readyState;
}
}
</script>
问题:在页面上点击导入按钮后为什么没有触发doUpload方法???(在方法里写了System.out.println("_____________")在Myeclipse后台没有输出)小弟新手,分不多~~请大虾别计较~~~~~
------解决方案--------------------
xmlHttp.open("POST","/jk/CLLock?user_id="+user_id,"true");
提交的url都不对
在jsp页面,无用代码我就不写了,
jsp 里面写的一个java doUpload方法
<% Ta060w sy = new Ta060w();
if (sy.handleIs("upload", pageContext)) {
String re= sy.doUpload(pageContext,"2");
Href hr = new Href("/jk/tactics/ta060w.jsp");
if("-2".equals(re) || "-1".equals(re)){
WebApp.redirect(pageContext, hr.toString(),"数据格式错误,导入不成功");
}else{
WebApp.redirect(pageContext, hr.toString(),"数据导入成功");
}
return;
}
%>
页面标记写了一个form表单:
<form name="form1" method="post" action="ta060w.jsp?handleType=upload" enctype="multipart/form-data">
<td colspan="2" align="center">
<input type="button" value="导 入" onclick="aa()">
<input type="reset" value="取 消"/>
</td>
</form>
在页面的js里面写的脚本,:
<script type="text/javascript">
function aa(){
obj = document.form1.reference;
var user = "<%=user_id%>";
var array = obj.value.split(".");
if(array[array.length-1]=="xlsx"){
toAjax(user);
}else{
alert("导入文件的后缀名必须是xlsx");
document.form1.reset();
}
}
function toAjax(user_id){
xmlHttp = createXMLHttpRequest();
xmlHttp.onreadystatechange = showDetailName;
xmlHttp.open("POST","/jk/CLLock?user_id="+user_id,"true");
xmlHttp.send(null);
}
function showDetailName(){
if(getCurrState(xmlHttp)==200){
var jsonList1=eval("("+xmlHttp.responseText+")");
if(jsonList1.length>0) {
document.form1.submit();
}else{
alert("由 "+jsonList1[2]["user_id"]+" 处理中...");
}
}
}
function createXMLHttpRequest(){
var xmlHttp;
if(window.ActiveXObject){
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if(window.XMLHttpRequest){
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
function getCurrState(xmlHttp){
if(xmlHttp.readyState==4){
if(xmlHttp.status==200){
return 200;
}else{
return xmlHttp.status;
}
}else{
xmlHttp.readyState;
}
}
</script>
问题:在页面上点击导入按钮后为什么没有触发doUpload方法???(在方法里写了System.out.println("_____________")在Myeclipse后台没有输出)小弟新手,分不多~~请大虾别计较~~~~~
------解决方案--------------------
xmlHttp.open("POST","/jk/CLLock?user_id="+user_id,"true");
提交的url都不对