1. 程式人生 > >jsp傳到java的control層的方法

jsp傳到java的control層的方法

xxxxx variable pat color tro import class 傳遞 select()

jsp傳到java的control層的方法
1.form表單 用<input type="submit">提交,提交到後臺的參數在form表單內
<form method="post" action="saveInfo">
  <input type="text" name="username">usrenamexxx</input>
  <input type="password" name="wpassword" id="wpassword" value="wpasswordxxx"/>
  <input type="submit" value="&nbsp;保存&nbsp;">
</form>
傳到後臺的路徑為:saveInfo方法post
後臺接收的方式是: @RequestMapping(value="saveInfo",method=RequestMethod.POST)
傳過來的值:username=usrenamexxx;wpassword=wpasswordxxx
2.a標簽
一、<a href="wantTowhere/${userid }/${wpassword}" style="color: #428bca;">xxxxxx</a>
假設${userid }=123;${wpassword}=abc;
則傳到後臺的路徑為:"wantTowhere/123/abc";
後臺接收的方式是: @RequestMapping(value="scoreImport/{userid}/{wpassword}")
          public String xxxx(@PathVariable Integer userid,@PathVariable Integer wpassword){
            return "";
          }
註:後臺{userid}和{wpassword}中變量可以和前臺不一樣。
傳過來的值:userid=123;wpassword=abc;
3.用方法傳遞
eg1:function classSelect(){
     window.location.href="<%=request.getContextPath()%>/pathxxx/"+"sid"+"/"+$(‘#s‘).val();
   }
sid可以是固定值或變量,$(‘#s‘).val()是id為s的輸入框或其它的值
則傳到後臺的路徑為:"wantTowhere/(sid的值)/(#s的值)";
後臺接收的方式是: @RequestMapping(value="scoreImport/{userid}/{wpassword}")
          public String xxxx(@PathVariable Integer userid,@PathVariable Integer wpassword){
            return "";
          }
eg2:function xxxSelect(){
    window.location.href="<%=request.getContextPath()%>/xxxselect?id="+$(‘#xxx‘).val();
  }
則傳到後臺的路徑為:xxxselect另外帶過去一個變量id=($(‘#xxx‘).val()的值);
後臺接收的方式是: @RequestMapping(value="xxxselect")
public String getlistSelect(Model model,Integer id){
  return xxx;
}
註:帶過去的變量名和方法中參數的名字必須一樣;
另:新遇到會再加進來,有錯的,或我沒加進來的,歡迎指正,謝謝!

jsp傳到java的control層的方法