JSP页面在localhost上查看。但Servelets设置问题。 (没有后端代码工作)

时间:2016-05-15 08:43:35

标签: java xml jsp tomcat

我对这个设置很新。我曾经在PHP上工作,这是完全不同的(我不知道如何使用xml进行设置)。

  

我已经安装了Tomcat。

     

我有项目的.war文件并将它们粘贴到tomact7/webapps/

     

我可以在localhost:8080/name_of_war_file

上的浏览器上查看我的页面

因此,.jsp页面没有任何麻烦。而servlets程序没有被执行(可能没有设置)。 例如:jsp页面中有表单操作,但它没有被调用。

  

tomcat7 / webapps中的文件夹结构:

     

Folder structure(在WEB-INF / classes / com / voting / dao,servelet,update等内部有很少.class个文件)

请注意.class个文件,而不是.java

以下是web.xml文件的内容

<?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/javaeehttp://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>VotingBallot</display-name>
<context-param>
    <description>Location to store uploaded file</description>
    <param-name>proof-upload</param-name>
    <param-value>C:\tmp\</param-value>
</context-param>

<servlet>
    <servlet-name>Init</servlet-name>
    <servlet-class>com.voting.servlet.InitServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>


<servlet>
    <servlet-name>Reg</servlet-name>
    <servlet-class>com.voting.servlet.RegisterServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Reg</servlet-name>
    <url-pattern>/register</url-pattern>
</servlet-mapping>



<servlet>
    <servlet-name>Reg2</servlet-name>
    <servlet-class>com.voting.servlet.Register2Servlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Reg2</servlet-name>
    <url-pattern>/register2</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>Login</servlet-name>
    <servlet-class>com.voting.servlet.LoginServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Login</servlet-name>
    <url-pattern>/login</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>Login2</servlet-name>
    <servlet-class>com.voting.servlet.Login2Servlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Login2</servlet-name>
    <url-pattern>/login2</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>Logout</servlet-name>
    <servlet-class>com.voting.servlet.LogoutServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>Logout</servlet-name>
    <url-pattern>/logout</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>electionList</servlet-name>
    <servlet-class>com.voting.servlet.ElectionListServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>electionList</servlet-name>
    <url-pattern>/electionList</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>votenow</servlet-name>
    <servlet-class>com.voting.servlet.VoteNowServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>votenow</servlet-name>
    <url-pattern>/votenow</url-pattern>
</servlet-mapping>

<servlet>
    <servlet-name>vote</servlet-name>
    <servlet-class>com.voting.servlet.VoteServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>vote</servlet-name>
    <url-pattern>/vote</url-pattern>
</servlet-mapping>
<servlet>
    <servlet-name>resultList</servlet-name>
    <servlet-class>com.voting.servlet.ResultListServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>resultList</servlet-name>
    <url-pattern>/resultList</url-pattern>
</servlet-mapping>


<servlet>
    <servlet-name>results</servlet-name>
    <servlet-class>com.voting.servlet.ResultsServlet</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>results</servlet-name>
    <url-pattern>/results</url-pattern>
</servlet-mapping>


<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>

此外,除了webapps / ROOT / META-INF之外,还有context.xml

<Context path="/" 
antiResourceLocking="false" >


    <Resource name="jdbc/voterdb" auth="Container" type="javax.sql.DataSource"
           maxActive="100" maxIdle="30" maxWait="10000"
           username="root" password="arun" driverClassName="com.mysql.jdbc.Driver"
           url="jdbc:mysql://localhost:8080/VotingBallot/"/>
</Context>

我有Java EE Eclipse,tomcat7,phpmyadmin作为DB查看器,能够查看jsp页面。

我希望能得到一些帮助。如果我在任何地方出错,我很抱歉。更多细节,我准备好了。

编辑: 这是表单操作代码段:

    <%
        String res = request.getParameter("res");
        if (res != null && res.equals("fail")) {
    %>
    <h3>Something went wrong. Please try again later.</h3>
    <%
        } else if (res != null && res.equals("new")) {
    %>
    <h3>EC Admin haven't approved your application yet. You will
        not be able to access this portal by this time.</h3>
    <%
        } else if (res != null && res.equals("rejected")) {
    %>
    <h3>Your application has been disabled by EC Admin. You will
        not be able to access this portal anymore.</h3>
    <%
        } else if (res != null && res.equals("approved")) {
    %>
    <h3>
        You have already been registered and your application is approved.
        You can login <a href='login.jsp'>here</a>.
    </h3>
    <%
        }
    %>
    <header>
        <h2>Voter Registration Form</h2>
        <p>All the fields are mandatory. .</p>
    </header>
    <form action='register' method=post id='reg'>
        <label> Enter your email: </label> <input type=text name='email' /><br>

        <label>Enter password:</label> <input type=password name='pw' /> <br>

        <label>Enter First name: </label> <input type=text name='fn' /><br>

        <label>Enter Last name:</label> <input type=text name='ln' /> <br>
        <label>Select Gender:</label> <select name='gen'>
            <option value='Male'>Male</option>
            <option value='Female'>Female</option>
        </select> <br> <br> <label>Enter Date of Birth</label> <input
            type=date name='dob' /> <br> <br> <label>Enter
            Mobile number</label> <input type=text name='mobile' /> <br> <label>
            Chose your assembly </label> <select name='assembly'>
            <option value="Mysore">Mysore</option>
            <option value="Bangalore">Bangalore</option>
            <option value="Hassan">Hassan</option>
        </select> <br> <br> <input type=submit value='PROCEED >>' /> <br>
        <br>
    </form>

0 个答案:

没有答案