黃滋滋
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: JAVA程式筆記-Servlet-1 tags: JAVA程式筆記 --- Servlet服務器(外部容器)端小程序(對應之前APPLET客戶端小程序) JAVAEE(Jakarta EE):客戶層--JAVA應用服務器--企業信息系統層 JAVA WEB服務器:TOMCAT 高級環境設定:這個也是一個雷(因為書裡沒有寫) https://www.itread01.com/content/1534426807.html?fbclid=IwAR2UBSmsJc2dr1FTas7ESHvE8ruOFSDa4xhdmmoxgmvTD58Mvhj4eZok9lE 參照網址打開+在USER的PATH裡加上JDK ![](https://i.imgur.com/05KFGD3.jpg) 也可以改成(只有在WINDOWS...但是這個%在學SPRING裝MAVEN時也有用到) ![](https://i.imgur.com/fuscO3y.jpg) 還有JAVA_HOME(我在想我之前TOMCAT都跳轉不成功,應該是沒有做到這裡) ![](https://i.imgur.com/nh2XAqP.jpg) 到CMD打JAVA可以看到指令: ![](https://i.imgur.com/YqCYgaH.jpg) ![](https://i.imgur.com/q2YsxsM.jpg) 因為我之前用過ESLIPSE所以我現在要用INTELLIJ IDEA(旗艦版)來練習 參考這個選項:https://blog.csdn.net/yhao2014/article/details/45740111 ![](https://i.imgur.com/xvUBYTN.jpg) 保護眼睛-字變大 ![](https://i.imgur.com/VCGcbUO.jpg) 我這裡TOMCAT是之前已裝好(難的就是XML裡的8080(基本上預設就是這個,只是怕自己在軟體外開了~軟體內又硬按~就衝突了)或?那裡有點難懂) https://juejin.im/post/5a75b0be5188254e761781d7?fbclid=IwAR0WcKmDPthL9MpjwRJBFQqwaS1eur2N1uC7wKOW7uZTWHT4pFwcufZKvhg 要記得V這個 WEB APPLICATION不然不會有生成到IDEA這個資料夾 ![](https://i.imgur.com/Un49oeO.jpg) ![](https://i.imgur.com/Uh1lAKM.jpg) SRC下建一個檔-HELLO一下 ![](https://i.imgur.com/Ax5Vexp.jpg) 結果 ![](https://i.imgur.com/gH8c14n.jpg) --- ![](https://i.imgur.com/5dtdaOg.jpg) SRC下建Servlet ![](https://i.imgur.com/OIPbkYl.jpg) 剛開始建好居然會反紅是正常,需要靠手工引入 ![](https://i.imgur.com/O9G88LD.jpg) ![](https://i.imgur.com/bTsmYum.png) ![](https://i.imgur.com/pp4C6fe.jpg) 發現在lib裡添加(每次做都要加一次) ![](https://i.imgur.com/nbVER98.jpg) --- doGet-客戶端提供的請求 HttpServletRequest request和http.HttpServletResponse https://www.itread01.com/content/1548390435.html response-應答/輸出流PrintWriter out=response.getWriter(); ![](https://i.imgur.com/c1gelqa.jpg) https://gist.github.com/jzs2home/953be404dcb577112a252f289c129c90 --- 然後還要改在web.xml的文件加入<servlet-mapping>的模板mapping(URL映射) ![](https://i.imgur.com/DZOju0x.jpg) https://gist.github.com/jzs2home/f5c935dc7159976a9f5ce774b5f8c353 然後也可以在web.xml裡面在加.jsp檔(歡迎頁面之類的) 第一次運行需要增加一些配置 ![](https://i.imgur.com/C2LHkNG.png) ![](https://i.imgur.com/uYK572b.png) 這個TOMCAT的地方我覺得也是一個雷 要注意自己的URL是在哪裡~大部分都是教8080.但是我這裡先改9999 ![](https://i.imgur.com/PScQZ5A.jpg) 然後還有一些網路上在教一些TOMCAT的設定時都會不知道為什麼這麼做時, 如果自己之前有亂改,記得的改回來,不然怎麼樣都看不到HELLOWORLD ![](https://i.imgur.com/Et1HkFE.png) 在旁邊那也要注意 ![](https://i.imgur.com/WP2TABD.png) 求到的結果 INTELLIJ最原本建好檔就有幫忙建一個index.jsp所以就會顯示這樣 ![](https://i.imgur.com/JwbcE1t.jpg) ![](https://i.imgur.com/mBKwjMl.jpg) 下面是要倒出我們建的/FirstServlet ![](https://i.imgur.com/ngRVj96.png) 改成國民練習題的+上名稱(還有加入些HTML的語法<h3></h3>) ![](https://i.imgur.com/kAfpc2Q.jpg) 結果(這裡只是改了.java+xml檔,其實比較雷的是TOMCAT和網址的KEY入,因為要很清楚才找的到):注意網址是要"自己用手打入?name=sonia(看你要打誰的名字都可以)"他不會自己生成 ![](https://i.imgur.com/hJrqOsK.jpg) ??的地方是中文亂碼,要編成中文的方法是~ 加入response.setContentType("text/html;charset=utf-8"); 記得要重啟(是從RUN到網頁都要全部關起來再開才會變,一直重新整理都不會變) ![](https://i.imgur.com/EvMxFyU.jpg) 結果~http://localhost:9999/FirstServlet?name=sonia(是從RUN到網頁都要全部關起來再開才會變,一直重新整理都不會變) ![](https://i.imgur.com/rDDhHfs.jpg) 從這裡也可以看客戶端名稱有沒有跑入 ![](https://i.imgur.com/7aVaA99.jpg) 也有人用"熱部屬模式就不用每次一直按RUN,不過比較特別的居然是要按DEBUG的鍵來重啟"(我是沒有用這個..因為沒差這個一點點的時間,BUG就做BUG的事) ![](https://i.imgur.com/YjcmYYg.png) --- 之前常常卡關在顯示了主網頁-A但是要跳到下一個B或C時跳不過去(後來發現是在Servlet裡建HTML檔?然後發生404/500時修改完程式碼要網頁關掉再重開~然後有些有的沒有的註解要刪掉像MAIN的地方~),之前看書時是寫建HTML檔,但是似乎是要建Servlet才是對的(後來發現是在Servlet裡建HTML檔?),來驗證看看~ https://hackmd.io/@sSA6NW2ZToCxgSaVETWNCg/r1Bmfza5U 也有人說就是把"右上"RUN的地方的"紅"的全部按暫停 tomcat在intellij的官方DEBUG https://www.jetbrains.com/help/idea/deploying-a-web-app-into-an-app-server-container.html?fbclid=IwAR3wDtZL2DKfDbdbhv7fWh6lgrA3W7jx4iKr6trvSBzN1y_MNjpoF3eqTg4 --- https://www.jetbrains.com/help/idea/run-debug-configuration-tomcat-server.html?fbclid=IwAR2dG_xq8p_lNvINZ5n7YxxhyUn2_klDMOOCu_2PnRa4rg1Jmp5paz40Fv4

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Google Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully