I am attempting to submit a post to a servlet that is running within tomcat on my own server. I want to submit a date and time parameter to the servlet post. The servlet is called fine, but I do not know how to access the parameters. They do not appear to be sent as request parameters. The following is a sample of the tag (note that date and time are field names declared in a field tag):
<submit next="http://<my ip address>/InvisentWeb/servlet/BestAvailableTimesServlet" method="post" namelist="date time" />
How can I submit this post request and get access to the date and time parameters in the servlet?
We've Moved! Please visit our new and improved forum over at our new portal: https://portal.plumvoice.com/hc/en-us/community/topics
How do I submit parameters to the servlet post?
Submitting data to a servlet or JSP document
Here is a simple servlet that handles 2 POST variables named "date" and "time"
since this is java code it needs to be compiled. A simpler, yet slower solution is to use a Java Server Page (JSP for short):
JSP works by generating the servlet and compiling it at run time. This has trade offs in that it simplifies the document, but is slightly more inefficient since it requires compiling the bytecode on demand. Regardless, either of these 2 methods should work for handling POST and GET data
hope this helps!![Smile :)](./images/smilies/icon_smile.gif)
Code: Select all
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SampleServlet extends HttpServlet{
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
String date = request.getParameter("date");
String time = request.getParameter("time");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//code goes here to return a valid html or vxml document
//out.println("string containing valid vxml or html doc goes here");
}
//if you wish to handle GET, uncomment this function and fill it in
/*
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException{
//GET variables are read in the same manner as POST variables
//eg:
//String sampleGetParameter = request.getParameter("sampleGetParameter");
}
*/
}
Code: Select all
<?xml version="1.0"?>
<vxml version="2.0">
<%@ page import="java.io.*" %>
<%
//setup the output object
PrintWriter out = null;
try{
out = response.getWriter();
}catch(IOException err){
//trap errors here
}
//get the parameters
String date = request.getParameter("date");
String time = request.getParameter("time");
%>
<form>
<block>
you entered date
<value expr="'<% out.println(date); %>'"/>
and time
<value expr="'<% out.println(time); %>'"/>
thank you, goodbye!
</block>
</form>
</vxml>
hope this helps!
![Smile :)](./images/smilies/icon_smile.gif)