java - pass parameter from jsp to another jsp dynamically -


i working on java application user's login , predict football matches , create admin jsp teams name stored table in database set week matches , set final results later when matches finish compare them users results , calculate points , top users etc ...

my admin.jsp choose matches team jstl foreach loop , set final result later compare them user prediction results.

<%@page import="pws.daoimp.usersdaoimp"%> <%@page import="java.lang.string"%> <%@page import="java.util.list"%> <%@page import="java.util.arraylist"%> <%@page import="pws.beans.users"%> <%@page contenttype="text/html" pageencoding="utf-8"%> <%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  <!doctype html>   <html>  <%       request.getattribute("admminresult"); %>  <%     list<string> teams1 = new arraylist();       usersdaoimp udi = new usersdaoimp();     list<string> admminresult = new arraylist();     admminresult = udi.getadminresult();     request.setattribute("admminresult", admminresult);     list<string> teams = new arraylist();     teams = udi.getallteams();     request.setattribute("teams", teams);    %>  <head>     <link rel="stylesheet" type="text/css" href="css/main.css" />     <meta http-equiv="content-type" content="text/html; charset=utf-8">     <title>match prediction</title>   </head> <body>      <div>     <h1 class="title">welcome match prediction site </h1>     <div id="logo" >         <img src="images/cl.png" alt="smiley face" width="142" height="142">     </div> </div> <form action ="adminuserhandling" method = "post" >      <div class="form-lables">         <h1><select name="clteam1" >                 <c:foreach items="${teams}"  var="teams"  >                     <option name="clm1g1" value="${teams}">                         ${teams}                     </option>                 </c:foreach>             </select> vs <select name="clteam1" >                 <c:foreach items="${teams}"  var="teams"  >                     <option name="clm1g1" value="${teams}">                         ${teams}                     </option>                 </c:foreach>             </select> </h1>         <label for="user_lic">goals : </label><input id="user_lic" name="clm1g1" type="number" min="" max="10" step="1" value ="1"/>         <label for="user_lic">goals : </label><input id="user_lic" name="clm1g2" type="number" min="" max="10" step="1" value ="1"/>     </div>       <input type ="submit" value="submit" />  </form>  </body> </html> 

and servlet code

 protected void dopost(httpservletrequest request, httpservletresponse response)         throws servletexception, ioexception {        usersdaoimp udi = new usersdaoimp();       response.setcontenttype("text/html;charset=utf-8");     printwriter out = response.getwriter();     string team1 = request.getparameter("clteam1");     string team2 = request.getparameter("clteam2");     string team1gl = request.getparameter("clteam1gl");     string team2gl = request.getparameter("clteam2gl");      users user = (users) request.getsession().getattribute("user");        system.out.println(team1);      system.out.println(team2);       udi.adminhandling(team1, team2,team1gl,team2gl); //save teams name , goals in database      processrequest(request, response); }   } 

my question set teams name , final result in admin page jsp have problem pass them users jsp dynamically , iam running out of ideas appreciated.

you can use requestdispatcher.

defines object receives requests client , sends them resource (such servlet, html file, or jsp file) on server. servlet container creates requestdispatcher object, used wrapper around server resource located @ particular path or given particular name.

requestdispatcher rd = request.getrequestdispatcher("/path/to/your/users.jsp"); // mention correct path user.jsp here request.setattribute("teams",teams); rd.forward(request, response); 

or

you can set object session.

 httpsession session = request.getsession(false);  session.setattribute("teams",teams); 

Comments

Popular posts from this blog

jOOQ update returning clause with Oracle -

java - Warning equals/hashCode on @Data annotation lombok with inheritance -

java - BasicPathUsageException: Cannot join to attribute of basic type -