This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General 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: 64824
86
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