开发工具:eclipse/idea/myeclipse/sts等均可配置运行
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
if(name==""||password==""){
alert("账号和密码都不能为空。");
return;
}
$.ajax({
url:'LoginSvlt',
data:{uname:name,upassword:password,utype:'cus'},
type:'post',
dataType:'json',
success:function(data){
if(data.msg==1){
window.location.href="index.jsp";
}else{
alert(data.msg);
}
}
});
}
</script>
</head>
<body>
<center>
<table cellspacing="0" cellpadding="0" style="border: 1px solid #C0C0C0">
<tr>
<td>
<jsp:include page="/top.jsp"></jsp:include>
e.printStackTrace();
}
}
configPath=f.getPath();
FileInputStream in = new FileInputStream(f);
props = new Properties();
props.load(in);
//关闭资源
in.close();
}
/**
* 根据key值读取配置的值
* @param key key值
* @return key 键对应的值
* @throws IOException
*/
public String readValue(String key) throws IOException {
return props.getProperty(key);
}
float: left !important;
}
.r{
float: right !important;
}
a{
text-decoration: none;
}
#header{
width:94%;
overflow: hidden;
height:75px;
padding:0 3%;
padding-top:25px;
background: #1b94db; /* Old browsers */
background: -moz-linear-gradient(bottom, #1b91d7 0%, #2297dd 33%, #1e93d6 53%, #2297dd 61%, #0781cc 100%);
background: -webkit-gradient(linear, bottom left, bottom left, color-sleft(0%,#1b91d7), color-sleft(33%,#2297dd), color-sleft(53%,#1e93d6), color-sleft(61%,#2297dd), color-sleft(100%,#0781cc));
background: -webkit-linear-gradient(bottom, #1b91d7 0%,#2297dd 33%,#1e93d6 53%,#2297dd 61%,#0781cc 100%);
background: -o-linear-gradient(bottom, #1b91d7 0%,#2297dd 33%,#1e93d6 53%,#2297dd 61%,#0781cc 100%);
background: -ms-linear-gradient(bottom, #1b91d7 0%,#2297dd 33%,#1e93d6 53%,#2297dd 61%,#0781cc 100%);
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#1b91d7', endColorstr='#0781cc',GradientType=0 );
background: linear-gradient(bottom #1b91d7 0%,#2297dd 33%,#1e93d6 53%,#2297dd 61%,#0781cc 100%);
}
.logo-left{
margin-top:10px;
String ezdid=request.getParameter("ezdid");
String stime=request.getParameter("stime");
String pval=request.getParameter("pval");
String ptype=request.getParameter("ptype");
String cxzh=request.getParameter("cxzh");
String yxsj=request.getParameter("yxsj");
boolean bl=db.insort("insert into piao(szdid,ezdid,tid,stime,pval,ptype,cxzh,yxsj) values("+szdid+","+ezdid+","+tid+",'"+stime+"',"+pval+",'"+ptype+"','"+cxzh+"','"+yxsj+"')");
if(!bl){
json.put("msg", "添加成功。");
}else{
json.put("msg", "添加失败");
}
}
PrintWriter out=response.getWriter();
out.print(json.toString());
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
this.doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
String stime=request.getParameter("stime");
String pval=request.getParameter("pval");
String ptype=request.getParameter("ptype");
String cxzh=request.getParameter("cxzh");
String yxsj=request.getParameter("yxsj");
boolean bl=db.insort("insert into piao(szdid,ezdid,tid,stime,pval,ptype,cxzh,yxsj) values("+szdid+","+ezdid+","+tid+",'"+stime+"',"+pval+",'"+ptype+"','"+cxzh+"','"+yxsj+"')");
if(!bl){
json.put("msg", "添加成功。");
}else{
json.put("msg", "添加失败");
}
}
PrintWriter out=response.getWriter();
out.print(json.toString());
out.flush();
out.close();
}
/**
* Initialization of the servlet. <br>
</tr>
<tr>
<td height="15" colspan="2"></td>
</tr>
<tr>
<td>始发站:</td>
<td>
<select style="width: 100px" id="gszdid" name="gszdid">
</select>
</td>
</tr>
<tr>
<td height="15" colspan="2"></td>
</tr>
<tr>
<td>终点站:</td>
request.setAttribute("tlist", tlist);
request.getRequestDispatcher("/admin/mgpiao.jsp").forward(request, response);
return;
}
//订票信息管理初始化
if("dpiao".equals(tname)){
ResultSet rs=db.query("select dpiao.*,cxzh,ezdid,ezdname,ptype,pval,stime,szdid,szdname,tid,tname,traintype,yxsj from(select tmp.*,zdname as ezdname from(select piao.*,zdname as szdname,tname,traintype from piao,zhandian,traininfo where piao.tid=traininfo.id and piao.szdid=zhandian.id)tmp,zhandian where tmp.ezdid=zhandian.id)tm,dpiao,cusinfo where tm.id=dpiao.pid and dpiao.cidcard=cusinfo.cidcard");
List<Dpiao> dplist=FindService.getDpiao(rs);
request.setAttribute("alist", dplist);
request.getRequestDispatcher("/admin/mdpiao.jsp").forward(request, response);
return;
}
//登录/注册跳转
if("dl".equals(tname)){
String sflag=request.getParameter("sflag");
request.setAttribute("sflag",sflag );
request.getRequestDispatcher("/login.jsp").forward(request, response);
return;
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html");
//设置传输数据编码方式
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
HttpSession session=request.getSession();
Object utype=session.getAttribute("utype");
Object userid=session.getAttribute("userid");
JSONObject json=new JSONObject();
if(utype==null||userid==null){
json.put("msg", "请重新登陆");
}else{
String opwd=request.getParameter("opwd");
String npwd=request.getParameter("npwd");
DbConn db=new DbConn();
String sql="";
if("gly".equals(utype.toString())){
sql="select id from userinfo where id="+userid+" and upassword='"+opwd+"'";
}else if("cus".equals(utype.toString())){
sql="select id from cusinfo where id="+userid+" and cpassword='"+opwd+"'";
}
boolean bl=false;
if("".equals(sql)){
json.put("msg", "系统错误01");
<html>
<head>
<base href="<%=basePath%>">
<title>管理员登陆</title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
<style type="text/css">
body
{
font-family: "宋体";
font-size: 9pt;
margin: 100px auto auto auto;
}
table
{
font-family: "宋体";
font-size: 9pt;
}
</style>
</head>
<script type="text/javascript" src="<%=basePath %>/Scripts/jquery-1.4.1.min.js"></script>
密码:
</td>
<td>
<input type="password" id="upassword" name="upassword" style="width: 100px;"/>
</td>
<td>
<input type="button" value="登 陆" onclick="lgbt();"/>
</td>
</tr>
</table>
</td>
</tr>
<tr onmousedown="dragStart(event)" onselectstart="return false;">
<td id="td2" style="height: 60px; text-align: center;">
<div id="div3" style="position: absolute; left: 0px; top: 0px; width: 600px; height: 60px; font-family:Comic Sans MS; color: #000000;">
</div>
<div id="div4" style="position: absolute; left: 0px; top: 0px; width: 600px; height: 60px; font-family:Comic Sans MS; color: #FFFFFF;">
</div>
</td>
</tr>
</table>
</div>
<input type="hidden" id="utype" value="gly"/>
</body>
</html>
<!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>
a.setEzdname(rs.getString("eaddr"));
a.setStime(rs.getString("stime"));
a.setTid(rs.getInt("tid"));
a.setTname(rs.getString("tname"));
a.setTraintype(rs.getString("traintype"));
String yx=rs.getString("yxsj");
if(yx.length()>10){
yx=yx.substring(0,10);
}
a.setYxsj(yx);
alist.add(a);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
return alist;
}
//将结果集转化成链表
public static List<Cusinfo> getCusinfo(ResultSet rs){
List<Cusinfo> alist=new ArrayList();
if(rs!=null){
try {
$(document).unbind("mousemove", dragMove);
$(document).unbind("mouseup", dragStop);
}
function lgbt(){
var un=$("#uname").val();
var up=$("#upassword").val();
if(un==""||up==""){
alert("请输入账号密码.");
return;
}
var ut=$("#utype").val();
$.ajax({
url:'LoginSvlt',
type:'post',
data:{uname:un,upassword:up,utype:ut},
dataType:'json',
success:function(data){
if(data.msg==1){
window.location.href="<%=basePath%>admin/main.jsp";
}else{
alert(data.msg);
}
}
/***
**/
$(function () {
$("#ckyxsj").datepicker();
$("#gyxsj").datepicker();
});
</script>
</head>
<body>
<center>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
}
package dp.svlt;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import dp.utils.DbConn;
import net.sf.json.JSONObject;
<script type="text/javascript" src="<%=basePath %>js/dtree.js"></script>
<script type="text/javascript" src="<%=basePath %>js/jquery.js"></script>
<script type="text/javascript">
window.onload=function(){
$("#con").css("height",$(document).height()-185);
}
</script>
<style type="text/css">
body{
padding:0;
margin:0;
}
div,ul,li,img,a,p{
padding:0;margin:0;
}
img{
border:0;
d.add(10202,102,'站点信息管理','Init?flgs=1&tname=zhandian',"",'page');
d.add(10203,102,'线路信息管理','Init?flgs=1&tname=initxl',"",'page');
d.add(103,1,'车票信息管理');
d.add(10301,103,'车票信息管理','Init?flgs=1&tname=piao',"",'page');
d.add(10302,103,'订票信息管理','Init?flgs=1&tname=dpiao',"",'page');
document.writeln(d);
</script>
</div></td>
</tr>
<tr>
<td height="31"><img src="<%=basePath %>images/menu_foot.gif" width="175" height="31"></td>
</tr>
</table></td>
<td id="con" height="100%" valign="top" align="center"><iframe src="<%=basePath %>Init?flgs=1&tname=admin" width="100%" height="100%" frameborder="0" scrolling="yes" name="page"></iframe></td>
</tr>
</table></td>
</tr>
</table>
</body>
import java.util.Properties;
import javax.servlet.http.HttpSession;
/**
* 读取Properties综合类,默认绑定到temp下的.properties文件。
*/
public class HandleProperties {
//配置文件的路径
private String configPath=null;
/**
* 配置文件对象
*/
private Properties props=null;
/**
* 默认构造函数,用于sh运行,自动找到temp下的.properties。
*/
public HandleProperties(HttpSession session,String fname) throws IOException{
String path=session.getServletContext().getRealPath("/");
File f=new File(path+"prop/"+fname+".properties");
if(!f.exists()){
f.getParentFile().mkdirs();
}
if(!f.exists()){
try {
f.createNewFile();
if("xianlu".equals(tname)){
String tid=request.getParameter("tid");
String zdid=request.getParameter("zdid");
String xh=request.getParameter("xh");
DbConn db2=new DbConn();
if(db.checkTrue("select id from xianlu where tid="+tid+" and zdid="+zdid)){
json.put("msg", "该线路已有该站点");
}else if(db2.checkTrue("select id from xianlu where tid="+tid+" and xh="+xh)){
json.put("msg", "站点序号已存在");
}else{
boolean bl=db.insort("insert into xianlu(xh,tid,zdid) values("+xh+","+tid+","+zdid+")");
if(!bl){
json.put("msg", "添加成功。");
}else{
json.put("msg", "添加失败");
var stime=$("#gstime").val();
var ezdid=$("#gezdid").val();
var ptype=$("#gptype").val();
var pval=$("#gpval").val();
var cxzh=$("#gcxzh").val();
var tid=$("#gtid").val();
var ids=$("#idi").val();
var flag=$("#flagi").val();
var yxsj=$("#gyxsj").val();
if(szdid==""||ezdid==""||stime==""||pval==""||cxzh==""||tid=="0"||yxsj==""){
alert('车票信息不完整。');
return;
}
if("add"==flag){
$.ajax({
url:'Add',
import net.sf.json.JSONObject;
public class HandlePiaoSvlt extends HttpServlet {
/**
* Constructor of the object.
*/
public HandlePiaoSvlt() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
运行环境
Java≥8、Tomcat≥8.0、MySQL≥5.7
开发工具
eclipse/idea/myeclipse/sts等均可配置运行
技术框架
JSP Servlet MySQL JDBC Tomcat CSS JavaScript
适用
课程设计,大作业,毕业设计,项目练习,学习演示等
功能说明
前台功能:用户查询车票信息、登录注册、购票、查看已购车票、修改密码等功能。
后台功能:管理员管理、用户管理、火车信息管理、站点信息管理、线路信息管理、车票信息管理、购票信息管理等。
后台:
前台