0

I'm new to this so i'm sure there is a simple solution but the question I'm trying to answer is this "This page should display a simple hello world message. In addition, your JSP page should look for a parameter in the request (GET) named “user”. If the user parameter is present, it should read the name from the request and display a greeting to the user. If the parameter is not present, it should display a generic “Hello World” message"

So far what I have is this:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World - JSP tutorial</title>
</head>
<body>
    <%= "Hello World!" %>
</body>
</html>

How would I go about adding the parameters?

  • you can use `request.getParameter("parameterName")` to get the parameter but first you need a good tutorial for jsp. – singhakash Sep 19 '15 at 18:12
  • Please go though link .Have you search before asking? [how-to-get-parameters-from-the-url-with-jsp-link][1] [1]: http://stackoverflow.com/questions/1890438/how-to-get-parameters-from-the-url-with-jsp – rupesh_padhye Sep 19 '15 at 18:15

1 Answers1

0

Here it goes:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Hello World - JSP tutorial</title>
</head>
<body>
<%
   String user = request.getParameter("user");
   response.getWriter().println(user == null ? ("Hello World") : ("Hello World " + user)); 
%>
</body>
</html>
Harish Sridharan
  • 1,070
  • 6
  • 10