This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes JSP and the fly likes jsp age verification code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp age verification code" Watch "jsp age verification code" New topic
Author

jsp age verification code

Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi,
In my small application , if age is >=20, it should display above20.jsp othewise below20.jsp.
in index.html two field USERNAME AND AGE.
I am getting below error while submitting it.

HTTP Status 500 -

--------------------------------------------------------------------------------

type Exception report

message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jasper.JasperException: An exception occurred processing JSP page /validuser.jsp at line 22

19: <%
20: String userid=request.getParameter("user");
21: String agge=request.getParameter("age1");
22: int i = Integer.parseInt("agge");
23:
24: if (i>20) {
25: %>


Stacktrace:
org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:505)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:416)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:337)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:390)


root cause



please help me

Thanks and Regards
thomas
Rajesh Kesarwani
Greenhorn

Joined: Apr 04, 2005
Posts: 23
Try below:

Index.html file:

<form action = "test.jsp">

<input type = "text" name = "userId" value = "" />
<input type = "text" name = "age" value = ""/>
<input type = "submit" name = "submit" value = "Click Here"/>

</form>

test.jsp file:

<%
String userId = request.getParameter("userId");
String age = request.getParameter("age");
int agge = 0;
if(age != null)
{
try
{
agge = Integer.parseInt("age");
}
catch(NumberFormatException e)
{
// age should be intered in number
}
}

if(agge >= 20)
{
%><%@include file = "above20.jsp"%><%
}
else
{
%><%@include file = "below20.jsp"%><%
}
%>

~Rajesh
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi Rajesh,
Thank you very much for your valuable suggestion.
After running you suggested code the following error was occured.

HTTP Status 404 - /WebApplication6/

--------------------------------------------------------------------------------

type Status report

message /WebApplication6/

description The requested resource (/WebApplication6/) is not available.


--------------------------------------------------------------------------------

Apache Tomcat/6.0.16

As i am building application using Netbeans 6.0.
Kindly suggest your updated view.

Thanks
thomas
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi Rajesh;
when i use above code, the request is go to only below20.jsp page.
for both age greter than 20 and less than 20 only below20.jsp get displayed.it doesnt satisfy condition.
Thanks and Regards
Thomas
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"thomas",
Please check your private messages.
-Ben


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Shilpa Tendulkar
Ranch Hand

Joined: Jul 29, 2001
Posts: 75
you should have Integer.parseInt(agge); instead of, Integer.parseInt("agge");


SCJP5
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"HARRY",
Please check your private messages regarding an important administrative matter.
-Ben
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi Shilpa;

you suggested code run successfully.
Now if i want to display the error page mentioning Age should be entered in Integer only, can you suggest any modification?
Thank you very much.

Regards
HARSHAL GURAV
Harshal Gurav
Ranch Hand

Joined: May 29, 2008
Posts: 151
Hi Shilpa;

you suggested code run successfully.
Now if i want to display the error page mentioning Age should be entered in Integer only, can you suggest any modification?
Thank you very much.

Regards
HARSHAL GURAV
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jsp age verification code
 
Similar Threads
problem in data insert using bean
SQL Server JDBC Connectivity Error
forEach not working
JDK 6 UPDATE 15, Includes JWSDP so it does not need install separatelly, like 5 ver?
Cannot be resolved to a type