pst = conn.prepareStatement("select * from admin where userName=?"); pst.setString(1,userName);
ResultSet rs=pst.executeQuery();
boolean isExist=false;
if(rs.next()){isExist=true;} out.println(isExist);
} catch (SQLException e) {
e.printStackTrace();
}
out.close();
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
public void init() throws ServletException {
}
}
4.3 web.xml配置文件中Servlet说明
…
<servlet>
<servlet-name>CheckUserName</servlet-name> <servlet-class>czz.com.CheckUserName</servlet-class>
</servlet>
<servlet_mapping>
<servlet-name>CheckUserName</servlet-name> <url-pattern>/CheckUserName</url-pattern>
</servlet-mapping>
…
4.4 运行效果
站点的部署在此不做讲述,运行成功后,如图2所示。用户可以输入信息进行注册了。
图 2 注册页面
|