button or using Ajax."/> button or using Ajax.">

Home  >  Article  >  Java  >  How to submit form in jsp

How to submit form in jsp

(*-*)浩
(*-*)浩Original
2019-05-16 11:33:342913browse

Speaking of JSP, of course submission of forms is indispensable. Summarize several methods of submitting forms in JSP.

Recommended course: Java Tutorial.

How to submit form in jsp

Submit via the

button

This method is the most traditional way to submit a form, which is to pass all the form values ​​to the url interface.

<%@ page language="java" contentType="text/html; charset=GB18030"
    pageEncoding="GB18030"%>
<meta http-equiv="Content-Type" content="text/html; charset=GB18030">
<title>Insert title here</title>
    <h1>测试servlet</h1>
    <hr>
        <form action="servlet/TestServlet" method="post" dir="ltr">
            <input name="userID" type="text"><br>
            <input value="查询" type="submit"><br>
        </form>

Pass

Here is the pass onclick triggers the js event, and then we can write some transmission methods in function onSubmit(){}, the more typical one is ajax transmission:

var j$ = jQuery.noConflict();//注册jQuery
function onSubmit(){
    j$.ajax({
        type:"get",
        url:"fix_project_contrast_do.jsp",
        data:{
            fixitem_id : j$("#fixitem_id").val(),
            check_man : j$("#check_man").val()
        },
        success:function(ret){
            if(ret == 1) {
                alert("提交审核成功!");
            }else{
                alert(ret);
                
            }
            window.returnValue=true;
            window.close();
        }
    });
}

Then we can process it in fix_project_contrast_do.jsp

<%@ page contentType="text/html; charset=GBK"  import="相应的类路径" %>

<%
try{
    
    Integer fixitem_id = Utility.trimNull(request.getParameter("fixitem_id")), new Integer(0));
    Integer check_man = Utility.parseInt(Utility.trimNull(request.getParameter("check_man")), new Integer(0));
    //处理逻辑省略
    out.clear();
    response.getWriter().write("1");//response相应值
}catch(Exception e){
    out.clear();
    response.getWriter().write(e.getMessage());
}

%>

The above is the detailed content of How to submit form in jsp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn