标签:hashcode osi Delve 验证 org poj size shc mic
https://mvnrepository.com
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.oracle.TestMavenWeb</groupId>
<artifactId>TestMavenWeb</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>TestMavenWeb Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>TestMavenWeb</finalName>
</build>
</project>
TestMavenWeb:
|---src
|----|---main
|----|----|---resources
|---pom.xml
Java Resources
|---src/main/java
|---src/main/resources
|---src/test/java
src
|---main
|----|---webapp
|----|----|---WEB-INF
|----|----|----|---web.xml
|----|----|---index.jsp
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
http://localhost:8080/TestMavenWeb/index.jsp
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.oracle.TestMavenServlet</groupId>
<artifactId>TestMavenServlet</artifactId>
<packaging>war</packaging>
<version>0.0.1-SNAPSHOT</version>
<name>TestMavenServlet Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
<!-- Java EE相关Jar文件配置 -->
<!-- https://mvnrepository.com/artifact/javax/javaee-api -->
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>8.0</version>
<scope>provided</scope>
</dependency>
<!-- MySQL数据库驱动Jar文件配置 -->
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.40</version>
</dependency>
<!-- C3P0数据库连接池Jar文件配置 -->
<!-- https://mvnrepository.com/artifact/com.mchange/c3p0 -->
<dependency>
<groupId>com.mchange</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.5.2</version>
</dependency>
</dependencies>
<build>
<finalName>TestMavenServlet</finalName>
</build>
</project>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>登录页面</title>
</head>
<body>
<h1>用户登录页面:</h1>
<form action="/TestMavenServlet/LoginServlet?method=login" method="post">
<table border="1px" cellpadding="3px" cellspacing="0px" width="30%">
<tr>
<td>用户手机号:</td>
<td>
<input name="phone" type="text" maxlength="11"/>
</td>
</tr>
<tr>
<td>用户密码:</td>
<td>
<input name="password" type="password"/>
</td>
</tr>
<tr>
<td colspan="2">
<input type="submit" value="提交登录"/>
<input type="reset" value="清空数据"/>
</td>
</tr>
</table>
</form>
</body>
</html>
public class C3P0ConnectionPool {
private static ComboPooledDataSource dataSource = new ComboPooledDataSource();
private C3P0ConnectionPool() {
}
public static Connection getConnection() {
Connection conn = null;
try {
conn = dataSource.getConnection();
conn.setAutoCommit(false);
}catch(Exception e) {
e.printStackTrace();
}
return conn;
}
}
public class UserServlet extends HttpServlet {
private static final long serialVersionUID = 8177420861630816913L;
private UserService userServie = new UserService(); //用于执行User相关业务逻辑的服务层对象
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String method = req.getParameter("method");
if("login".equals(method)) {
userServie.login(req, resp);
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
resp.setCharacterEncoding("utf-8");
doGet(req, resp);
}
}
<!-- 对UserServlet的配置信息 -->
<servlet>
<servlet-name>UserServlet</servlet-name>
<servlet-class>com.oracle.servlet.UserServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UserServlet</servlet-name>
<url-pattern>/UserServlet</url-pattern>
</servlet-mapping>
public class UserService {
private UserDAO userDao = new UserDAOImpl(); //用于数据库查询的DAO对象
/**
* 执行用户登录的Service方法
* @param req
* @param res
* @throws Exception
*/
public void login(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
//[1]获取前端页面的表单数据
String phone = req.getParameter("phone");
String password = req.getParameter("password");
//[2]查询用户的登录结果
boolean loginSuccess = userDao.queryUserLogin(phone, password);
//[3]如果用户登录成功,则查询用户名
String username = "";
if(loginSuccess) {
username = userDao.queryUsernameByPhone(phone);
}
//[4]编织响应页面,返回用户登录结果
resp.setContentType("text/html;charset=utf-8");
PrintWriter pw = resp.getWriter();
pw.println("<!DOCTYPE html>");
pw.println("<html>");
pw.println("<head>");
pw.println("<meta charset=\"utf-8\">");
pw.println("<title>");
pw.println("登录结果页面");
pw.println("</title>");
pw.println("</head>");
pw.println("<body>");
pw.println("<h1>");
if(loginSuccess) {
pw.println("欢迎" + username + "用户回来!");
}else {
pw.println("登录失败!");
}
pw.println("</h1>");
pw.println("</body>");
pw.println("</html>");
pw.flush();
}catch(Exception e) {
e.printStackTrace();
}
}
}
public class User {
private Integer uId;
private String username;
private String password;
private String phone;
public User() {
super();
}
public User(Integer uId, String username, String password, String phone) {
super();
this.uId = uId;
this.username = username;
this.password = password;
this.phone = phone;
}
public User(String username, String password, String phone) {
super();
this.username = username;
this.password = password;
this.phone = phone;
}
//后续getter/setter方法和equals方法、hashCode方法、toString方法原码省略
...
}
public interface UserDAO {
/**
* 通过用户电话号码和用户密码查询用户登录是否成功的方法
* @param phone 用户电话号码
* @param password 用户密码
* @return 用户是否存在
* @throws SQLException
*/
public boolean queryUserLogin(String phone, String password) throws SQLException;
/**
* 通过用户手机号码查询用户名的方法
* @param phone 用户手机号码
* @return 用户名
* @throws SQLException
*/
public String queryUsernameByPhone(String phone) throws SQLException;
}
public class UserDAOImpl implements UserDAO {
@Override
public boolean queryUserLogin(String phone, String password) throws SQLException {
Connection conn = C3P0ConnectionPool.getConnection();
String sql = "select count(*) from User where phone = ? and password = ?";
PreparedStatement stat = conn.prepareStatement(sql);
stat.setString(1, phone);
stat.setString(2, password);
ResultSet resultSet = stat.executeQuery();
int result = 0;
if(resultSet.first()) {
result = resultSet.getInt(1);
}
if(result == 1) {
return true;
}
return false;
}
@Override
public String queryUsernameByPhone(String phone) throws SQLException {
Connection conn = C3P0ConnectionPool.getConnection();
String sql = "select username from User where phone = ?";
PreparedStatement stat = conn.prepareStatement(sql);
stat.setString(1, phone);
ResultSet resultSet = stat.executeQuery();
String username = "";
if(resultSet.first()) {
username = resultSet.getString("username");
}
return username;
}
}
<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>From JSP</title>
</head>
<body>
<%String webPath = application.getContextPath();%>
<h1>进行跳转的JSP页面</h1>
<!-- 使用一般的JSP代码获取跳转的目标路径 -->
<a href="<%=webPath%>/jsp/target.jsp">GO! GO! GO!</a>
</body>
</html>
<%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Target JSP</title>
</head>
<body>
<%String webPath = application.getContextPath();%>
<h1>跳转到的JSP页面</h1>
</body>
</html>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
<installed facet="jst.jaxrs" version="2.0"/>
<installed facet="jst.jsf" version="2.2"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="jst.web" version="3.0"/>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.0"/> <!-- 将version的取值改变为3.0 -->
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="jst.jaxrs" version="2.0"/> <!-- 新加入的内容 -->
<installed facet="jst.jsf" version="2.2"/> <!-- 新加入的内容 -->
</faceted-project>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>Archetype Created Web Application</display-name>
</web-app>
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>Archetype Created Web Application</display-name>
</web-app>
标签:hashcode osi Delve 验证 org poj size shc mic
原文地址:https://www.cnblogs.com/noyitela/p/10386455.html