java - How to use sendRedirect or session or forward to refresh my web page only one time? -


now in page have parameter call personid,if visitor input url :http://helloworld.com?personid=123,and return person information whitch personid 123.i can not known whether person real.so decide when person visit page first time,i use sendredirect , attatch other parameter.but way wrong.can use session or other way refresh page 1 time?

    <%  string personid = request.getparameter("personid "); string vpersonid= request.getparameter("vpersonid");  if (vpersonid== null) {   string url="http://myserver/distinguishusrtoken.do?redirect_uri=http://helloworld.com/index.jsp?personid=123&personid ="+personid ;      response.sendredirect(url); }  %> 

when people visit web http://helloworld.com?personid=123,the final url http://helloworld.com?personid=123&ppersonid=123;but if people see keyword , input url http://helloworld.com?personid=123&ppersonid=123 directly,althought fake url,but can not anything.how redirect self page 1 time?i try use session,but endless loop?

    <%   string personid = request.getparameter("personid ");  string vpersonid = request.getparameter("vpersonid ");   if(response.getheader("personid")==null||!personid.equals(response.getheader("personid"))){ string url="http://myserver/distinguishusrtoken.do?redirect_uri=http://helloworld.com/index.jsp?personid=123&personid ="+personid ;   vpersonid =personid ;  response.setheader("personid ", personid ); response.sendredirect(url);   }  %> 

every time come such situation, recommend rethink architecture and/or approach. instance, current problem, i'd suggest toward filters. allow keep servlets , jpss free not specific tasks them. i'm not going post code here, 'cause question bit general, , rather recommend take @ examples of filters in internet. example here.

btw, added tag spring question, can suppose use spring framework in application. if true, framework can take on lot of things, don't need extract request parameters manually.


Comments