(2)使用myeclipse建立servlet步驟:繼承HttpServlet開發servlet

來源:互聯網
上載者:User

myeclipse支援jsp/servlet/structs/hibernate/spring…..
步驟:
①使用IDE建立web工程:web server project
②在src中建立包
③在包中new —servlet 一般把URL改為類名
④配置Tomcat 注意要選enable
⑤發布(複製檔案) 選擇Project 然後選擇伺服器server
⑥啟動Tomcat

需求:post方式提交,並將提交的資訊在網頁中顯示

package  com.jdj;import javax.servlet.*;import javax.servlet.http.*;import java.io.*;public class myhttpServlet extends HttpServlet{    //回憶<form action="提交給誰" method="post|get"/>預設是get     protected void doGet(HttpServletRequest req,                     HttpServletResponse resp)              throws ServletException,                     java.io.IOException{           resp.getWriter().println("i am httpservlet doGet()");          }      protected void doPost(HttpServletRequest req,                      HttpServletResponse resp)               throws ServletException,                      java.io.IOException{             resp.getWriter().println("i am httpservlet doPost()"+req.getParameter("username"));         }}

在WEB-INF平級目錄中寫login

<html>    <body>       <form action="/jdjweb/myhttpServlet" method="post">       使用者名稱:<input type="text" name="username"/>    <input type="submit" value="登陸"/>   </body></html>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.