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

How to submit form in jsp

(*-*)浩
Release: 2019-05-24 14:19:02
Original
2975 people have browsed it

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>
Copy after login

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();
        }
    });
}
Copy after login

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());
}

%>
Copy after login

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!

Related labels:
jsp
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template