Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Syntax

 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a servlet which receives input from a form, processes the data and sends response to a JSP.
public class A extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws IOException, ServletException
{
String name =req.getParameter("name");
String city = req.getParameter("city");
String country = req.getParameter("country");
welcome.jsp? inname= name& incity=city & incountry=country;
}
}
I want to pass the 3 strings to a JSP welcome.jsp.
<%
String jspName = request.getParameter("inname");
String jspCity = request.getParameter("incity");
out.println("Welcome "+ jspName);
out.println("You live in "+ jspCity);
%>
Is the abpve correct in the servlet and jsp?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65105
89
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happened when you tried it?
 
Lucky Singh
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks. I got it.
 
Afroz Ahmed
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,
Try this code to send the parameters to the welcome file...
<a href="welcome.jsp?incity='"+ <%= city %> + "'& incountry='" +
<%= country % > + " '">
or
String s="welcome.jsp?incity='"+ city + "'& incountry='" +
country + " '";
<a href="<%= s %>" >
I hope the above one will work.

Regards
Afroz Ahmed(SCJP 1.4)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic