jsp - Servlets birthday calculator tomcat -
can see if there errors in code servlet should able send data next servlet cant compile myself cause tomcat keeps giving several ports in use error though restarted tomcat services , tomcat/bin it... tried restarting pc tried searching 8080 port , closed ans still same
protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { response.setcontenttype("text/html"); printwriter out = response.getwriter(); out.print("<html>"); out.print("<body>"); out.println("<form action='end' method='post'>"); out.println("month " + "<select>" + "<option mon=1>january</option>" + "<option mon=2>febuary</option>" + "<option mon=3>march</option>" + "<option mon=4>april</option>" + "<option mon=5>may</option>" + "<option mon=6>june</option>" + "<option mon=7>july</option>" + "<option mon=8>august</option>" + "<option mon=9>october</option>" + "<option mon=10>september</option>" + "<option mon=11>october</option>" + "<option mon=12>decmeber</option>" + "</select>"); out.println("day " + "<select>" + "<option day=1>1</option>" + "<option day=2>2</option>" + "<option day=3>3</option>" + "<option day=4>4</option>" + "<option day=5>5</option>" + "<option day=6>6</option>" + "<option day=7>7</option>" + "<option day=8>8</option>" + "<option day=9>9</option>" + "<option day=10>10</option>" + "<option day=11>11</option>" + "<option day=12>12</option>" + "<option day=13>13</option>" + "<option day=14>14</option>" + "<option day=15>15</option>" + "<option day=16>16</option>" + "<option day=17>17</option>" + "<option day=18>18</option>" + "<option day=19>19</option>" + "<option day=20>20</option>" + "<option day=21>21</option>" + "<option day=22>22</option>" + "<option day=23>23</option>" + "<option day=24>24</option>" + "<option day=25>26</option>" + "<option day=27>27</option>" + "<option day=28>28</option>" + "<option day=29>29</option>" + "<option day=30>30</option>" + "<option day=31>31</option>" + "</select>"); out.println("year " +"<select>" + "<option yr=1996>1996</option>" + "<option yr=1997>1997</option>" + "<option yr=1998>1998</option>" + "<option yr=1999>1999</option>" + "<option yr=2000>2000</option>" + "<option yr=2001>2001</option>" + "<option yr=2002>2002</option>" + "<option yr=2003>2003</option>" + "<option yr=2004>2004</option>" + "<option yr=2005>2005</option>" + "<option yr=2006>2006</option>" + "<option yr=2007>2007</option>" + "<option yr=2008>2008</option>" + "<option yr=2009>2009</option>" + "<option yr=2010>2010</option>" + "<option yr=2011>2011</option>" + "<option yr=2012>2012</option>" + "<option yr=2013>2013</option>" + "<option yr=2014>2014</option>" + "</select>"); out.println("<input type='submit' value='submit'>"); out.println("</form>"); out.print("</body>"); out.print("</html>");}
will send servlet
protected void dopost(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception { int bdaymon=integer.parseint(request.getparameter("mon")); int bdayday=integer.parseint(request.getparameter("day")); int bdayyr=integer.parseint(request.getparameter("yr")); int fxmon=4; int fxday=23; int fxyr=2015; int calcmon= 0; int calcday= 0; int calcyr = 0; response.setcontenttype("text/html"); printwriter out = response.getwriter(); out.print("<html>"); out.print("<body>"); if(bdaymon>fxmon){ calcyr=fxyr-bdayyr-1; calcmon=(12-bdaymon)+(fxmon)-1; if(bdayday<fxday) calcday=fxday-bdayday; else if(bdayday>fxday) calcmon--; else calcmon=0;} if(bdaymon<fxmon){ calcyr=fxyr-bdayyr; calcmon=fxmon-bdaymon; if(bdayday<fxday) calcday=fxday-bdayday; else if(bdayday>fxday) calcmon--; else calcmon=0;} if(bdaymon==fxmon){ calcyr=fxyr-bdayyr-1; calcmon=(12-bdaymon)+(fxmon)-1; if(bdayday<fxday) calcday=fxday-bdayday; else if(bdayday>fxday) calcmon--; else calcmon=0;} out.print("you " + calcyr + "years" + calcmon + "months" + calcday + "days"); out.print("</body"); out.print("</html>"); }
}
the question run or not if not why? please dont criticize way code our college prof slow , dosent know doing , besides pretty sleepy when coded yeah flawed logic
the code provide run fine. i'm running code with:
- eclipse luna
- tomcat 7
- dynamic web application server (version 2.5)
as mentioned fix error can change tomcat port configuration. see details available on how change tomcat default port
Comments
Post a Comment