小编Jse*_*sel的帖子

在提交之前进行表单验证的最佳方法是什么

请有人建议我,

在提交之前进行表单验证的最佳方法是什么?

实际场景就像,我有一个名为保存的按钮,所以当用户按下保存按钮时。

我需要验证数据并将流传递给服务器以将数据存储在表中。

除了在服务器端进行表单数据验证之外,是否有任何可能的方法来检查客户端本身的表单数据

<form>
    <header>
        <h1>Testing </h1>
    </header>
    <p>
        Receipt number:
        <input type="text" id="grn" class="tb1" onkeypress="return isNumber(event)" /> Type
        <select name="evalu" id="evalu">
            <option value="electrical">Electrical</option>
            <option value="mechanical">Mechanical</option>
        </select>
        cad
        <select name="cd" id="cd">
            <option value="unit1">xv</option>
            <option value="unit2">ed</option>
        </select>
        <input type="button" id="find" value="Find" class="button0" />
        <br>
        <br> Report No
        <input type="text" name="irepno" id="irepno" class="tb1" maxlength="8" /> date
        <input type="text" name="idt" id="idt" class="tb1" value="<%= new SimpleDateFormat(" dd-MM-yyyy ").format(new java.util.Date())%>">
        <input type="button" id="search" value="Search" class="button0" />
        <br></br>
        <input type="button" value="Save the record" id="saverecord" …
Run Code Online (Sandbox Code Playgroud)

javascript jquery servlets

4
推荐指数
1
解决办法
5655
查看次数

构造函数 JSONObject(String) 是未定义错误 - 无法解析

我试图获取 servlet 中的一些变量,这些变量都是通过 ajax 调用传递的。但我收到构造函数 JSONobject(string) 未定义错误。我也导入了所需的库。请帮忙

import com.google.gson.Gson;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.reflect.TypeToken;

import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.json.*;


public class insertserv extends HttpServlet {
	private static final long serialVersionUID = 1L;
	
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{    
		
		System.out.println("I am inside insert");
	    String json = "";
		
		
		BufferedReader br = new BufferedReader(new InputStreamReader(request.getInputStream()));
	   

	            if (br != null) {
	                json = br.readLine();
	            }
	 
	   System.out.println(json);
	   
	   JSONObject wholedata= new JSONObject(json);
		
				
	   response.setContentType("application/json"); 
		PrintWriter out= response.getWriter(); …
Run Code Online (Sandbox Code Playgroud)

java json servlets

0
推荐指数
1
解决办法
8235
查看次数

标签 统计

servlets ×2

java ×1

javascript ×1

jquery ×1

json ×1