我有一个问题,它不检查我输入的文本是否只是字母?我真的不知道如何在 jsp 和 Ajax 中编写 javascript?有人可以通过发布一个我可以学习的好链接来提供帮助吗?尤其是使用Ajax调用数据库
这是我现在遇到的问题,我如何检查文本大小是否大于 0
<%@page import="java.util.*,support.*,java.sql.*"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%//javascript file %>
<script>
function allLetter(value)
{
var letters = /^[A-Za-z]+$/;
if(inputtxt.value.match(alphaExp))
{
return true;
}
else
{
alert("message");
return false;
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Names and country of residence page</title>
</head>
<body>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
// Registering Postgresql JDBC driver with the DriverManager
Class.forName("org.postgresql.Driver");
// Open a connection to the database using DriverManager
conn = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/assignment1",
"postgres","Km81920265");
// Create the statement
Statement statement = conn.createStatement();
// Use the created statement to SELECT
// the student attributes FROM the Student table.
rs = statement.executeQuery("SELECT * FROM countries_and_states WHERE is_country='t'");
%>
<%//first delcare input %>
Please enter your first name, last name and middle initial:<p>
<form method="get" action="address.jsp">
<%//store input into session %>
Your first name :<input type="text" size="15" name="firstName" onchange="allLetter(this.value); "/><p/>
Your last name : <input type="text" size="15" name="lastName"/><p/>
Your middle name:<input type="text" size="15" name="middleName"/><p/>
<%//display dropdown menu using for looop %>
Provide country information menu:<p>
Country:
<select name="Countryid">
<%
while(rs.next()){
%>
<option value="<%=rs.getInt("cs_id")%>"><%=rs.getString("country_state")%>
</option>
<%} %>
</select>
<p>
<%-- -------- Close Connection Code -------- --%>
<%
// Close the ResultSet
if(rs != null){
rs.close();
}
// Close the Statement
statement.close();
// Close the Connection
conn.close();
%>
<%///closing up the entry page and submit the data %>
<input type="submit" value="Submit Personal Data" onclick="this.disabled=true;"/>
</form>
</body>
</html>