程序没有正确执行

时间:2014-04-13 16:04:34

标签: html mysql jsp

抱歉所有长代码......但是......为了让我能够使用我的程序并解决一些问题,我需要它才能真正起作用。我正在使用.html和.jsp文件将数据插入MYSQL数据库。任何人都可以告诉我为什么我得到这个:这个页面无法显示,请确保地址http:// localhost:8081是正确的... ???请帮忙,谢谢!

<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Help Desk Ticket System</title>
</head>
<body>
<script language ="JAVASCRIPT">

function check(form)
{

    if(form.equipment.value =="")
    {
        alert("Please enter equipment type")
        form.equipment.focus()
        return false
    }

    if(form.problem.value =="")
    {
        alert("Please enter a description before hitting submit")
        form.problem.focus()
        return false
    }


    if(form.empid.value =="")
    {
        alert("Please enter employee ID.")
        form.empid.focus()
        return false
    }

    if(form.empfname.value =="")
    {
        alert("Please enter a  first name.")
        form.empfname.focus()
        return false
    }

    if(form.emplname.value =="")
    {
        alert("Please enter a last name.")
        form.emplname.focus()
        return false
    }

    if(form.empemail.value =="")
    {
        alert("Please enter your email")
        form.empemail.focus()
        return false
    }

    if(form.empphone.value =="")
    {
        alert("Please enter a your phone number.")
        form.empphone.focus()
        return false
    }

    if(form.empcellphone.value =="")
    {
        value = "n/a"
    } 

    selected = form.empdept.selectedIndex   
    if (selected<=0)
    {
        alert("Please choose the department")
        form.empdept.focus()
        return false
    }

selected = form.technician.selectedIndex    
    if (selected<=0)
    {
        alert("Please choose a technician")
        form.technician.focus()
        return false
    }

    alert("Your ticket has been created.")
    return true
}
</script>

<FORM method="post" action="http://localhost:8081/finalproject/help.jsp" onsubmit="return check(this)">

<h2> Please fill out the following details for your ticket </h2>
<br/>

Equipment: <input type="text" name="equipment" /><br/>
<br/>
Description of the problem: <br/>
<textarea name="problem" rows="4" cols="50"></textarea><br/>
<br/>
<hr>
<br/>

Employee ID: <input type = "text" name="empid" /><br/>
Employee First name: <input type = "text" name="empfname" /><br/>
Employee Last name: <input type = "text" name="emplname" /><br/>
Employee email: <input type = "text" name="empemail" /><br/>
employee Phone: <input type = "text" name="empphone" /><br/>
employee cell Phone: <input type = "text" name="empcellphone" /><br/>
<br/>
Employee Department: <br/>
<select name = "empdept">
  <option> Please select the department</option>
  <option>Marketing</option>
  <option>Human Resources</option>
  <option>Operations</option>
   <option>Legal</option>
  <option>Accounting</option>
  <option>Production</option>
</select>
<hr>
<br/>

Choose Technician: <select name ="technician">
  <option value="0">Select</option>
  <option value="12345">Sierra: Applications </option>
  <option value="12344">Michael: Network</option>
  <option value="12343">Greg: Phones</option>
  <option value="12342">Aaron: Hardware</option>
  <option value="12341">Phil: Database </option>

</select><br/>
<br/>

<br/>
         <button type="submit">Submit</button>   <button type="reset" value="Clear Form">Reset</button>

</form>
</body>
</html>



  <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>

<%@ page import="java.sql.*" %>
<%@ page import="java.util.Random" %>

<% 
Connection conn = null;
Statement st = null;
ResultSet rs = null;

//Random rand = new Random();
//int randomnumber = rand.nextInt(90000) + 10000;

try 
{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:mysql://localhost/helpdesk?user=root&password=password");

    st = conn.createStatement();

//String ticket = request.getParameter("ticketid");
String a = request.getParameter("equipment");
String b = request.getParameter("problem");

String c = request.getParameter("empid");
String d = request.getParameter("empfnname");
String e = request.getParameter("emplname");
String f = request.getParameter("empemail");
String g = request.getParameter("empphone");
String h = request.getParameter("empcellphone");
String i = request.getParameter("department");

String j = request.getParameter("technician");
String jointables = ("Select tech_id from technician inner join ticket on technician.tech_id = ticket.tech_id;");

String insert1 = ("insert into ticket (t_date,t_equpipment, t_descript,emp_id,tech_id)" + 
" values( NOW(),'"+a+"', '"+b+"', '"+c+"', '"+j+"')");

String insert2 = ("insert into employee (emp_id, emp_fname,emp_lname,emp_email, emp_phone,emp_cellphone,emp_dept)" +
"values ('"+ c +"','" + d + "','" + e + "','" + f + "','" + g + "','"+ h +"','" + i + "')");

String intodatabase = insert1 + insert2;
out.println("<b>Executed the following SQL statement:</b><br>");
out.println(intodatabase);  //print out the actual sql statement that was generated
//Execute the "insert into" sql statement
st.executeUpdate(intodatabase);
out.println ("<br><br><b>Successfully Added the tuple..</b>");
}

catch (java.sql.SQLException ex) 
{
     out.println("<br><b>Ouch, an SQLException was thrown..</b>");
        ex.printStackTrace();
}

finally 
{
    if (rs != null) rs.close();
    if (st != null) st.close();
    if (conn != null) conn.close();
}

%>

</body>
</html>

0 个答案:

没有答案