Skip to content

Commit

Permalink
hzuapps#4 提交实验代码
Browse files Browse the repository at this point in the history
  • Loading branch information
Danivy committed Oct 20, 2016
1 parent 73b44f7 commit 456cc03
Show file tree
Hide file tree
Showing 5 changed files with 179 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package edu.hzu.javaweb.labs.se1414080902205;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/1414080902205")
public class Se1414080902205Servlet extends HttpServlet {

/**
*
*/
private static final long serialVersionUID = 1L;

public Se1414080902205Servlet() {
super();
}


public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

// response.setContentType("text/html");
// PrintWriter out = response.getWriter();
// out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
// out.println("<HTML>");
// out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
// out.println(" <BODY>");
// out.print(" This is ");
// out.print(this.getClass());
// out.println(", using the GET method");
// out.println(" </BODY>");
// out.println("</HTML>");
// out.flush();
// out.close();
doPost(request,response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text/html");
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
PrintWriter out = response.getWriter();
String Account = new String(request.getParameter("account"));
String Amount = new String(request.getParameter("amount"));
// out.print(Account);
// out.print(Amount);
if (Account.equals("")) {
out.println("账号不能为空");
} else if (Amount.equals("")) {
out.println("转账金额不能为空");
} else {
boolean flat = true;
char[] str=Account.toCharArray();
for (int i = 0;i < Account.length();i++) {
int x = str[i] - '0';
if (!(x >= 0 && x <= 9)) {
out.println("请输入正确的账号");
flat = false;
break;
}
}
if (flat) {
char[] sstr =Amount.toCharArray();
for (int i = 0;i < Amount.length();i++) {
int x = sstr[i] - '0';
if (!(x >= 0 && x <= 9)) {
out.println("请输入正确的转账金额");
flat = false;
break;
}
}
}
if (flat) out.println("转账成功");
}
// String Account = "1414080902205";
// String Amount = "1414080902205";
// out.println(Account);
// out.println(Amount);
// out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
//// out.println("<HTML>");
//// out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
//// out.println(" <BODY>");
//// out.print(" This is ");
//// out.print(this.getClass());
//// out.println(", using the POST method");
//// out.println(" </BODY>");
//// out.println("</HTML>");
//// out.flush();
//// out.close();
}

public void init() throws ServletException {
// Put your code here
}

}
3 changes: 3 additions & 0 deletions jweb/web/1414080902205/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Class-Path:

Binary file not shown.
17 changes: 17 additions & 0 deletions jweb/web/1414080902205/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<description>This is the description of my J2EE component</description>
<display-name>This is the display name of my J2EE component</display-name>
<servlet-name>Se1414080902205Servlet</servlet-name>
<servlet-class>edu.hzu.javaweb.labs.se1414080902205.Se1414080902205Servlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Se1414080902205Servlet</servlet-name>
<url-pattern>/servlet/Se1414080902205Servlet</url-pattern>
</servlet-mapping>

</web-app>
50 changes: 50 additions & 0 deletions jweb/web/1414080902205/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<link href="http://cdn.bootcss.com/bootstrap/3.3.0/css/bootstrap.min.css" rel="stylesheet">
</head>
<title>
ATM Transfer
</title>
<body>
<div class="Register">
<h2 class="text-center"> ATM Transfer </h2>
<center>Now time is:
<%=new java.util.Date()%>
</center>
<form id="register" action="servlet/Se1414080902205Servlet" method="post">
<div class="form-group">
<label for="username1">Account *</label>
<input type="text" id="Account" class="form-control" />
</div>
<div class="form-group">
<label for="password1">Amount *</label>
<input type="password" id="Amount" class="form-control"/>
</div>
<div style = "text-align:right;">
<button type="button" class="btn btn-default">Confirm</button>
</div>
</form>
</div>

</body>
<script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script>
<script src="http://cdn.bootcss.com/bootstrap/3.3.0/js/bootstrap.min.js"></script>
<script type="text/javascript">
$( ".btn" ).click(function() {
//alert(".btn");
var Account = $("#Account").val();
var Amount = $("#Amount").val();
$.ajax({
url: "servlet/Se1414080902205Servlet",
data:{account: Account,amount:Amount},
type : "post",
datatype:"html",
success: function(data){
alert(data);
}});
});
</script>

</html>

0 comments on commit 456cc03

Please sign in to comment.