我的servlet出错了

时间:2017-11-27 05:27:06

标签: javascript java jquery html

我是Java的初学者。我必须创建一个登录servlet,我试图在Tomcat 7中运行它,但我的项目没有运行。请帮帮我。

我在Tomcat中运行状态为false。我有两种类型的用户。一个是管理员,另一个是客户。当管理员的相关登录页面显示并且客户将重定向到相关页面时,客户可以添加客户端,并且在此客户中可以向其客户发送批量电子邮件。 500封电子邮件,差距为10秒,如何做到这一点。

我在tomcat日志文件中收到此错误。 (2017年11月27日下午5:05:19 org.apache.catalina.startup.HostConfig deployDirectory 严重:部署Web应用程序目录C:\ Program Files \ Apache Software Foundation \ Tomcat 7.0 \ webapps \ admin时出错 java.lang.IllegalStateException:ContainerBase.addChild:start:org.apache.catalina.LifecycleException:无法启动组件[StandardEngine [Catalina] .StandardHost [localhost] .StandardContext [/ admin]]     在org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:898)     在org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:871)     在org.apache.catalina.core.StandardHost.addChild(StandardHost.java:615)     在org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1095)     在org.apache.catalina.startup.HostConfig $ DeployDirectory.run(HostConfig.java:1617)     at java.util.concurrent.Executors $ RunnableAdapter.call(Executors.java:471)     at java.util.concurrent.FutureTask $ Sync.innerRun(FutureTask.java:334)     at java.util.concurrent.FutureTask.run(FutureTask.java:166)     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:615)     在java.lang.Thread.run(Thread.java:722)))

here is a screen shot of tomcat

index.html

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" href="bootstrap/bootstrap.min.css">
     <link rel="stylesheet" type="text/css" href="css/cust-login.css">
      <link rel="stylesheet" type="text/css" href="css/pure-min.css">
      <script src="bootstrap/jquery.min.js"></script>
</head>
<body>
<div class="header-page">

    </div>
    <div class="header-two" >       
    </div>

<br>
<br>
<div class="cust-login-form">
        <div class="cust-login-form-align">
        <form class="pure-form pure-form-stacked" method="post" action="login">
    <fieldset>
        <legend><img src="image/LOGO.png" height="50px">Custmer Login Form</legend>

        <label for="email">Email</label>
        <input id="email" type="email" placeholder="Email" name="email">
        <span class="pure-form-message">This is a required field.</span>

        <label for="password">Password</label>
        <input id="password" type="password" placeholder="Password" name="pass">



        <label for="remember" class="pure-checkbox">
            <input id="remember" type="checkbox"> Remember me
        </label>

        <button type="submit" class="pure-button pure-button-primary">Sign in</button>
    </fieldset>
</form>
</div>
    </div>
</body>
</html>


login.java

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
public class login extends HttpServlet 
{
    public void doPost(HttpServletRequest req,
        HttpServletResponse res)
        throws ServletException,
        IOException
    {
        res.setContentType("text/html");
        PrintWriter pw=res.getWriter();
        String u=req.getParameter("email");
        String p=req.getParameter("pass");
        String userad="komal@gmail.com";
        String passwrd="admin";
        RequestDispatcher rd;
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/adminpanel","root","root");
            PreparedStatement stmt=con.prepareStatement("select * from custdetails where email=? AND password=?");
            stmt.setString(1,u);
            stmt.setString(2,p);
            ResultSet rs=stmt.executeQuery();
            while(rs.next()){
        if(userad.equals(u) && passwrd.equals(p))
        {
            HttpSession session=req.getSession();
            System.out.print(session.isNew());//true
            rd=req.getRequestDispatcher("/adminpanel.html");
            rd.forward(req,res);
            return;
        }   
        else if (u.equals(rs.getString(6)) && p.equals(rs.getString(5))) {
            HttpSession session=req.getSession();
            System.out.print(session.isNew());//true
            rd=req.getRequestDispatcher("/addcustomer.html");
            rd.forward(req,res);
            return;
        }
        else{
        PrintWriter out=res.getWriter();
        out.print("Invalid user or password");
        rd=req.getRequestDispatcher("/index.html");
        rd.include(req,res);
            }
        }
    }
        catch(Exception e)
            {
                out.println(e);
            }
        }
}




regcustclnt.java

import javax.servlet.ServletException;
import javax.servlet.http.*;
import java.io.*;
import java.sql.*;
import javax.servlet.http.HttpServlet;
//import javax.servlet.http.HttpRequest;
//import javax.servlet.http.HttpResponse;

public class regcustclnt extends HttpServlet{

    public void doPost(HttpServletRequest req,HttpServletResponse res)throws ServletException,
        IOException{
        res.setContentType("text/html");
        PrintWriter out=res.getWriter();
        String name=req.getParameter("name");
        String contact=req.getParameter("contact");
        String email=req.getParameter("email");
        String address=req.getParameter("address");
        String profession=req.getParameter("profession");
        Connection con=null;
        Statement stmt=null;
        try{
            Class.forName("com.mysql.jdbc.Driver");
            }catch(ClassNotFoundException ex){
                ex.printStackTrace();
            }
            try{
                con=DriverManager.getConnection("jdbc:mysql://localhost:3306/adminpanel","root","root");
                stmt=con.createStatement();
                String query="insert into custClientdetail values('"+name+"','"+contact+"','"+email+"','"+address+"','"+profession+"')";
                stmt.execute(query);
                out.print("<h1>you have added a new customer..!");
            }
            catch(SQLException ex){
                out.print("error in inserting data");
                ex.printStackTrace();
            }

            finally{

                try{
                    stmt.close();
                }
                catch(SQLException ex){}

                try{
                    con.close();
                }
                catch(SQLException ex){}
            }




    }
}



logout.java

import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
public class logout extends HttpServlet 
{
    public void service(HttpServletRequest req,
        HttpServletResponse res)
        throws ServletException,
        IOException
    {
        HttpSession session=req.getSession(false);
        session.invalidate();
        RequestDispatcher rd=req.getRequestDispatcher("/index.html");
        rd.include(req,res);
    }
}


web.xml

    enter code here

<web-app>
    <servlet>
        <servlet-name>login</servlet-name>
        <servlet-class>login</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>login</servlet-name>
        <url-pattern>/login</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>regcustclnt</servlet-name>
        <servlet-class>regcustclnt</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>regcustclnt</servlet-name>
        <url-pattern>/regcustclnt</url-pattern>
    </servlet-mapping>
    <servlet>
        <servlet-name>logout</servlet-name>
        <servlet-class>logout</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>logout</servlet-name>
        <url-pattern>/logout</url-pattern>
    </servlet-mapping>
</web-app>


adminpanl.html


<!DOCTYPE html>
<html>
<head>
    <title></title>
     <meta name="viewport" content="width=device-width, initial-scale=1">
     <link rel="stylesheet" href="bootstrap/bootstrap.min.css">
     <link rel="stylesheet" type="text/css" href="css/style.css">
      <link rel="stylesheet" type="text/css" href="css/pure-min.css">
      <script src="bootstrap/jquery.min.js"></script>
      <script type="text/javascript" src="js/form.js"></script>
</head>
<body>

    <div class="pag-header">
        <h3><img src="image/LOGO.png" height="50px">ADMINSTRATION</h3>
    </div>

<div class="next-page-header">
        <div class="nav-menu">

            <span class="menu"><a href="admin.html">Add Customer  |&nbsp;&nbsp;</a>
            <a href="about us">View Customer  |&nbsp;&nbsp;</a>
            <a href="gallery">gallery  |&nbsp;&nbsp;</a>
            <a href="portfolio">portfolio  |&nbsp;&nbsp;</a>
            <a href="contact">contact</a>

            </span>
    <a href="logout" style="float:right">LOGOUT</a>


    </div>

    </div>
    <div class="form-header">
    <div class="cust-form">
        <h4>Add_Customer<button type="button" id="add" style="float:right;height:30%" class="btn-style">ADD</button></h4>

    </div>


    </div>

<div class="main-form-width" id="main-form" style="display:none">
    <div class="main-form">
    <form method="post" acttion="insrt" class="pure-form pure-form-aligned">
    <fieldset>
        <div class="pure-control-group">
            <label for="name">Name</label>
            <input id="name" type="text" placeholder="Name" name="name">
            <span class="pure-form-message-inline">This is a required field.</span>
        </div>
         <div class="pure-control-group">
            <label for="contact">Contact</label>
            <input id="contact" type="text" placeholder="Contact" name="contact">
            <span class="pure-form-message-inline">This is a required field.</span>
        </div>
        <div class="pure-control-group">
            <label for="uname">Username</label>
            <input id="uname" type="text" placeholder="Username" name="username">
            <span class="pure-form-message-inline">This is a required field.</span>
        </div>

        <div class="pure-control-group">
            <label for="password">Password</label>
            <input id="password" type="password" placeholder="Password" name="pass" >
        </div>

        <div class="pure-control-group">
            <label for="email">Email Address</label>
            <input id="email" type="email" placeholder="Email Address" name="email">
        </div>

        <div class="pure-control-group">
            <label for="foo">Address</label>
            <textarea id="foo" type="text" placeholder="Address"  name="address"></textarea>
        </div>
        <div class="pure-control-group">
            <label for="bname">BusinessName</label>
            <input id="bname" type="text" placeholder="BusinessName" name="bsname">
        </div>

            <div class="pure-control-group">
            <label for="logo">Logo</label>
            <input id="logo" type="file" placeholder="upload file" name="upfile">
        </div>
       <!-- <div class="pure-controls">
            <label for="cb" class="pure-checkbox">
                <input id="cb" type="checkbox"> I've read the terms and conditions
            </label>-->

            <button type="submit" class="pure-button pure-button-primary" style="margin-left:10%">Submit</button>
        </div>
    </fieldset>
</form>
    </div>

</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您可以使用线程发送邮件,这也可以让您设置时间。请参阅multiThreading概念