---
# System prepended metadata

title: JSP/Servlet learn 30 Day

---

# JSP/Servlet learn 30 Day

___
### Day 1
___
 1. Install Tomcat
 2. Install Eclipse IDE
 3. Create Servlet.java
 **(編輯 java package 跟 Class name 按到下一步要把自動產生 web.xml檔打勾**
 ![](https://i.imgur.com/4uLdzTX.png)
** @WebServlet("/LoginServlet") 是對應的URL**
 
 4.新增 Server Runtime
 
**project左鍵-> Bulid Path-> Configure Bulid Path-> 選Libraries-> Classpath 欄按 Add Library->Server Runtime-> 選剛下載的Tomcat-> Finish**

5. 設定web.xml(在WEB-INF 把web.xml設定方式加進來,調整成只要url有/,後面不管接什麼就直接呼叫Servlet)
  
          <servlet>
            <servlet-name>LoginServlet</servlet-name>
            <servlet-class>com.servlet.LoginServlet</servlet-class>
          </servlet>

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

6. 新增 login.jsp and index2.jsp(index2是因為預設是index會直接讀取到所以改名子）

        <form action="LoginServlet" method="post">
        <div >
            <table>
            <tr>
            <td>
                <h1>User Name:</h1><input type="text" name="name"  />
            </td>
            </tr>
            <tr>
            <td>
                <h2>Password:</h2><input type="password" name="mypassword" >
                <input type="submit" value="submit">
            </td>
            </tr>
            </table>
        </div>
        </form>

7. 
     
     
