--- title: JAVA程式筆記-JSP~登入 tags: JAVA程式筆記 --- 在學SPRING時會用到的JAVA BEAN: 1.必須要有java.io.Serializable import java.io.Serializable; --- 2.get.../set...(intellij按右鍵可以選..這個是學校考題..是有一定的格式寫法) 3.編變數第一個字母一定要小寫 userid --- 4.初始值 this.userid = 0; this.userName = ""; --- 5.非公有 6.User()要是空的() package com.zhijieketang; import java.io.Serializable; public class User implements Serializable { int userid; String userName; public User() { this.userid = 0; this.userName = ""; } public int getUserid() { return userid; } public void setUserid(int userid) { this.userid = userid; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } } --- 使用<jsp:forward>跳轉到其他網頁 要注意一個要有一個PACKAGE(要自己按右鍵建)(沒有這個只有練習HELLO會動,其他都不會,有些課本附的CODE打開不能RUN就是這個,不過建議在複製檔案前要先用HELLO試試自己的TOMCAT連線是否正常~因為像自己就會手賤一直按RUN) JAVA檔 ![](https://i.imgur.com/P4RqYJY.png) JSP檔 ![](https://i.imgur.com/buSp1kL.png) --- 覺得比較特別的是在<%%>中包了} 後來發現如果不能成功跳轉~是因為按RUN卡住了~TOMCAT太多訊號要一起GO ![](https://i.imgur.com/9oPzizE.png) 下面 ![](https://i.imgur.com/Hu10552.png) DEPLOYMENT那頁 ![](https://i.imgur.com/QcYNzxn.png) DEPLOYMENT那頁下面 ![](https://i.imgur.com/2cetZgu.png) 而且要RUN要從login.jsp的地方按RUN然後再按軟體上的網頁(讓他自己轉比較可以知道自己的路徑在哪裡~) ![](https://i.imgur.com/pevmipk.png) // if 驗證通過,forward-->sucess.jsp //else forward-->login.jsp --- 正常輸入帳號密碼完會產生一個是否要記住的訊號 if (name.equals("sonia") && password.equals("123")) ![](https://i.imgur.com/lA3g4jV.png) KEY ![](https://i.imgur.com/ad6Y0HM.png) --- .JSP的範例(成功跳轉) 需要鍵的檔案有.java擋(Servlet)+.jsp擋(非常多個) ![](https://i.imgur.com/nkGL0Ge.jpg) MyServlet.java檔 https://gist.github.com/jzs2home/e8bd85ac9cbad71a31f15733970244fb user檔(就是有get和set那個) https://gist.github.com/jzs2home/b2ca063b873d2d8116e008e7df5d62b9 login.jsp(要記得是RUN這個) https://gist.github.com/jzs2home/04465e7d2a5584f51746504ceffd448c checklogin.jsp帳密正確會跳頁~不然.... https://gist.github.com/jzs2home/f55fb000be4ccd52c48da7532a1975e3 sucess.jsp(登入成功的頁面) https://gist.github.com/jzs2home/52aae4ec92b67d87af98e05c31668bb3 結果~雖然我的純Servlet的跳轉還是不會動,但是JSP會動就好(應該是因為不是用html),反正結果一樣 ![](https://i.imgur.com/d3MSgH7.jpg) 後面想要再把JDBC再複習一下~ https://hackmd.io/@sSA6NW2ZToCxgSaVETWNCg/BJLolkys8