java怎么让表单不提交_java - 提交按钮清除表单而不发布

因此,我尝试使用一种简单的形式从用户获取输入,从数据库中检索必要的信息,然后将其发布。但是,在HTML页面上,“提交”按钮仅会清除表单。以下是该操作中引用的html文件和java文件。我知道与数据库交互的文件丢失了,但我认为问题出在这两个问题之一。如果需要,我可以稍后发布。我的问题是,为什么提交按钮会清除表单而不是使您进入“行动”网站?

Class 1:

Class 2:

Class 3:

Class 4:

import java.io.*;

import java.util.*;

import javax.servlet.*;

import javax.servlet.http.*;

public class Schedule extends HttpServlet {

public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {

PrintWriter toClient = res.getWriter();

String field;

String val;

Vector classes = null;

Vector totalHours = null;

String query = null, query2 = null;

String class1 = null, class2 = null, class3 = null, class4 = null;

int i, sum=0;

res.setContentType("text/html");

toClient.println("");

toClient.println("

MyEcho");

toClient.println("

");

Enumeration values = req.getParameterNames();

if( values.hasMoreElements() ) {

class1 = req.getParameter("Class 1");

class2 = req.getParameter("Class 2");

class3 = req.getParameter("Class 3");

class4 = req.getParameter("Class 4");

toClient.println("

Your Schedule:

");

query = "select * from csci_section where number = " + class1 + " or number = " + class2 + " or number = " + class3 + " or number = " + class4 + ";";

}

query2 = "select credit from csci_section where number = " + class1 + " or number = " + class2 + " or number = " + class3 + " or number = " + class4 + ";";

if( query == null )

toClient.println("

No query given; resubmit ");

else if(1==1) { //if the request did not return anything, i.e. the number given is not a class

} else{

toClient.println("

Running search for classes: " + class1 + ", " + class2 + ", " + class3 + ", " + class4 + ", " + "

" );

classes = AccessMySQL.Execute( query );

totalHours = AccessMySQL.Execute(query2);

toClient.println("

Received classes:

");

for( i = 0; i < classes.size(); i++ ){ //prints out info

toClient.println( "

" + (String)classes.elementAt( i ) + "

" );

}

for(i=0; i < totalHours.size(); i++){

sum += Integer.parseInt((totalHours.elementAt(i)).toString());

}

toClient.println("

The total number of class hours is: " + sum + "

" );

}

toClient.println( "" );

toClient.println("");

toClient.close();

} //closes doPost

}

最佳答案

因为您有两个

标记。第一个(不执行任何操作)是浏览器用户使用的。删除它,它应该会按预期开始工作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值