Forwarding A Servlet Post Variables
Hello, I'm trying to forward some posted variables from form A to this servlet where I am adding one more then forwarding it on. How can I get it to forward and show up in the URL window instead of how I'm doing it here with the servlet context?
package com.shoponlinesecure.order;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
public class AddHashAndForward extends HttpServlet {
public void doPost(HttpServletRequest request,
HttpServletResponse response)throws ServletException, IOException {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
out.write(AuthorizeNetFingerPrint.insertFP("wil481306225","AMONaKPAIXGdLUgB","10.50",
"789", null));
out.close();
RequestDispatcher dispatcher =
getServletContext().getRequestDispatcher("https://secure.authorize.net/gateway/transact.dll");
dispatcher.forward(request, response);
}-thanks
This is basically what I'm trying to do in java without any javascript. They have this thing as you can see called a <%ret variable%> that only gets executed when you hit the submit button. I'm trying to do it the way I am becuase I do not want to use javascript to simulate the asp ret variable. So I thought I forwarded it to a servlet that added it then forwarded it to the gateway I would be ok?
Example 1 � Minimum requirements for requesting a Payment Form
The following HTML code along with the server-side script represents the minimum data that would need to be inserted into a page to provide a connection to the system. It shows that the fingerprint, time stamp, and the sequence number are inserted into the HTML form POST along with Login ID and other required fields. The result of this HTML code snippet is a button. Clicking on the button will take the user to the gateway�s Payment Form.
A call to generate the fingerprint should be made when the button is clicked and before the Payment Form request is made to the gateway. A sequence number should be generated and the total amount of the tranaction calculated before the call to generate the fingerprint is made. The function used to generate the fingerprint takes these fields (amount, transaction key, Login ID, and sequence number) The transaction amount should not change after the fingerprint is generated. All trailing spaces need to be removed from the fields used to generate the fingerprint
<!--#INCLUDE FILE="simlib.asp"-->
<FORM METHOD=POST ACTION="https://secure.authorize.net/gateway/transact.dll">
<% ret = InsertFP (loginid, txnkey, amount, sequence) %>
<INPUT TYPE=HIDDEN NAME="x_login" VALUE="your login ID goes here">
<INPUT TYPE=HIDDEN NAME="x_show_form" VALUE="PAYMENT_FORM">
<INPUT TYPE=HIDDEN NAME="x_amount" VALUE="amount goes here">
<INPUT TYPE=SUBMIT VALUE="Click here for secure payment form">
</FORM>
The function InsertFP is provided by the gateway and can be downloaded from the Merchant Interface. This function must be called within a server-side script on the merchant Web server. The above example shows the call being made in an ASP scripting environment.
Similar Messages
-
Hello to all,
I build a site based on the JSP - servlet technology . My problem is that I want to post variables from JSP to servlet and vise vera without reveal their value to the end user through the URL. I am using the setAttribute parameter but by this way even user's password is visible in the url. I 've heard that there is an invisible way posting variables, but I don't know how. Does anybody know how this can be done?
Tnx in advanceYou use <form method="post">
This prevents the request parameters from being shown in the URL.
request.setAttribute() will not affect the URL at all - it is the preferred way to pass values between jsps and servlets when using the requestDispatcher at the servlet end.
Cheers,
evnafets -
Spry XML data set and dynamic post variables
Hi,
I am trying to create an XML data set that has dynamic post
variables.
Everytime something is pressed on the page a variable changes
and I then want to reload the XML data set using the new variable.
I know I can just pull in an XML with all possible variables
and filter client side but this would make it way too large.
Does anyone know what I may need to do.
I tried this:
var myVar = 0;
var dss = new Spry.Data.XMLDataSet (
'../../cgi-bin/server_details.pl' , 'top' , { method: 'POST' ,
postData: sid=ajaja21&ip=127.0.0.1&cid=' . myVar ,
subPaths: [ "auth" , "plugins" , "plugins/plugin" ] , keepSorted:
"true", sortOnLoad: "plugins/plugin/order", sortOrderOnLoad:
"descending", useCache: false, loadInterval: 10000 } );
onclick="myVar=1";
But the script doesn't understand the post variables sent (it
does when I remove the . myVar part and put in a static value). I
think it isn't sending that dynamic variable with the post
variables.
Any ideas anyone?
ThanksWell I had it working when I stripped back everything and
just had the dss data set and a single onclick function, but now
that I put it back together it hash foobared again.
Here are the relevant bits of code that I've changed.
The function to change server id:
//function to run when changing the server id
function changeServer ( sid ) {
//set the url to use the current server id
dss.setURL = ( '../../cgi-bin/server_details.pl' , { method:
'POST' , postData:
'sid=7gv1m3vjvagfl7h7qeefb8iodj8evhmb&ip=127.0.0.1&cid='+sid
//force a reload of the server data
dss.loadData();
The inital load of the data set
var dss = new Spry.Data.XMLDataSet (
'../../cgi-bin/server_details.pl' , 'yams' , { method: 'POST' ,
postData:
'sid=7gv1m3vjvagfl7h7qeefb8iodj8evhmb&ip=127.0.0.1&cid=0' ,
subPaths: [ "auth" , "plugins" , "plugins/plugin" ] , keepSorted:
"true", sortOnLoad: "plugins/plugin/order", sortOrderOnLoad:
"descending", useCache: false, loadInterval: 10000 } );
And the part that changes the server id
<td align="left" style="cursor:default; width:174px;"
onclick="changeServer({dsv::servers/server/@id})">{dsv::servers/server/name}</td>
I checked that the function is receiving the correct server
id and I even tried hard coding the cid variable to 2 in the change
function but it still wasn't changing on the server side.
Any ideas?
Thanks -
Hi all,
i have bean package cedars;
import java.util.Hashtable;
import java.util.*;
public class FormBean {
private String name = null;
private String stuNumber = null;
private String facultyName= null;
private String quesOne = null;
private String quesTwo = null;
private String quesThree = null;
private String quesFour= null;
private String quesFive= null;
private String quesSix= null;
private String quesSeven= null;
private String quesEight= null;
private String quesNine= null;
private String quesTen= null;
private String quesEleven= null;
private String quesTwelve= null;
private String quesThirteen= null;
private String quesFourteen= null;
private String quesFifteen= null;
private String quesSixteen= null;
private String quesSeventeen = null;
private String quesEighteen=null;
private String quesNineteen=null;
private String quesTwenty=null;
private String quesTwentyOne=null;
private Hashtable errors = new Hashtable();
public boolean validate() {
boolean allOk=true;
if (stuNumber.equals("")|| stuNumber.length() !=10) {
errors.put("stuNumber","Please enter a valid student Number");
stuNumber="";
allOk=false;
} else {
try {
int x = Integer.parseInt(stuNumber);
} catch (NumberFormatException e) {
errors.put("stuNumber","Please enter a valid student Number");
stuNumber="";
allOk=false;
}//else
return allOk;
public String getErrorMsg(String s) {
String errorMsg =(String)errors.get(s.trim());
return (errorMsg == null) ? "":errorMsg;
public FormBean () {
again();
/* Name */
public String getName() {
return (this.name);
public void setName(String name) {
this.name = name;
/* Student number */
public String getStuNumber(){
return (this.stuNumber);
public void setStuNumber(String stuNumber){
this.stuNumber = stuNumber;
/* gender */
private String gender= null;
public String getGender(){
return (this.gender);
public void setGender(String gender) {
this.gender = gender;
/*college*/
public String getFacultyName(){
return (this. facultyName);
public void setFacultyName(String facultyName){
this. facultyName=facultyName;
/*degree*/
String degree=null;
public String getDegree() {
return (this.degree);
public void setDegree(String degree){
this.degree =degree;
/* year */
private String year = null;
public String getYear() {
return (this.year);
public void setYear(String year){
this.year = year;
/*question one */
public String getQuesOne() {
return (this.quesOne);
public void setQuesOne(String quesOne){
this.quesOne = quesOne;
/*question two */
public String getQuesTwo() {
return (this.quesTwo);
public void setQuesTwo(String quesTwo){
this.quesTwo = quesTwo;
/*question Three */
public void setQuesThree(String quesThree){
this.quesThree = quesThree;
/*question four */
public String getQuesFour() {
return (this.quesFour);
public void setQuesFour(String quesFour){
this.quesFour = quesFour;
/*question five */
public String getQuesFive() {
return (this.quesFive);
public void setQuesFive(String quesFive){
this.quesFive = quesFive;
/*question six */
public String getQuesSix() {
return (this.quesSix);
public void setQuesSix(String quesSix){
this.quesSix =quesSix;
/*question seven */
public String getQuesSeven(){
return (this.quesSeven);
public void setQuesSeven(String quesSeven){
this.quesSeven =quesSeven;
/*question Eight */
public String getQuesEight() {
return (this.quesEight);
public void setQuesEight(String quesEight){
this.quesEight =quesEight;
/*question Nine */
public String getQuesNine() {
return (this.quesNine);
public void setQuesNine(String quesNine) {
this.quesNine =quesNine;
/*question Ten */
public String getQuesTen(){
return (this.quesTen);
public void setQuesTen(String quesTen){
this.quesNine =quesTen;
/*question Eleven*/
public String getQuesEleven(){
return (this.quesEleven);
public void setQuesEleven(String quesEleven) {
this.quesEleven =quesEleven;
/* question Twelve*/
public String getQuesTwelve(){
return (this.quesTwelve);
public void setQuesTwelve(String quesTwelve) {
this.quesTwelve =quesTwelve;
/* question Thirteen**/
public String getQuesThirteen() {
return (this.quesThirteen);
public void setQuesThirteen(String quesThirteen) {
this.quesThirteen =quesThirteen;
/*question Fourteen*/
public String getQuesFourteen() {
return (this.quesFourteen);
public void setQuesFourteen(String quesFourteen) {
this.quesFourteen =quesFourteen;
/* question Fifteen*/
public String getQuesFifteen(){
return (this.quesFifteen);
public void setQuesFifteen(String quesFifteen) {
this.quesFifteen =quesFifteen;
/* question Sisteen*/
public String getQuesSixteen(){
return (this.quesSixteen);
public void setQuesSixteen(String quesSixteen) {
this.quesSixteen =quesSixteen;
/* question Seventeen */
public String getQuesSeventeen (){
return (this.quesSeventeen );
public void setQuesSeventeen (String quesSeventeen ) {
this.quesSeventeen=quesSeventeen ;
/* question Eighteen*/
public String getQuesThree(){
return (this.quesThree);
public String getQuesEighteen (){
return (this.quesEighteen );
public void setQuesEighteen(String quesEighteen ){
this.quesEighteen =quesEighteen ;
/*question Nineteen*/
public String getQuesNineteen(){
return (this.quesNineteen );
public void setQuesNineteen(String quesNineteen ){
this.quesNineteen =quesNineteen ;
/*Twenty*/
public String getQuesTwenty(){
return (this.quesTwenty );
public void setQuesTwenty(String quesTwenty ){
this.quesTwenty =quesTwenty ;
/*Twenty-One*/
public String getQuesTwentyOne(){
return (this.quesTwentyOne );
public void setQuesTwentyOne(String quesTwentyOne ) {
this.quesTwentyOne =quesTwentyOne ; }
public void setErrors(String key, String msg) {
errors.put(key,msg);
public void again(){
setName("");
setStuNumber("");
setGender("");
setFacultyName("");
setDegree("");
setYear("");
setQuesOne("");
setQuesTwo("");
setQuesThree("");
setQuesFour("");
setQuesFive("");
setQuesSix("");
setQuesSeven("");
setQuesEight("");
setQuesNine("");
setQuesTen("");
setQuesEleven("");
setQuesTwelve("");
setQuesThirteen("");
setQuesFourteen("");
setQuesFifteen("");
setQuesSixteen("");
setQuesSeventeen("");
setQuesEighteen("");
setQuesNineteen("");
setQuesTwenty("");
setQuesTwentyOne("");
}and process.jsp
%@ page import="java.util.*" %>
<html>
<head>
<jsp:useBean id="formHandler" class="cedars.FormBean" scope="request">
<jsp:setProperty name="formHandler" property="*"/>
</jsp:useBean>
<%
if (formHandler.validate()) {%>
<jsp:forward page="/servlet/Insert"/>
<% } else { %>
<jsp:forward page="/resubmit.jsp"/>
<% } %>
</body>
</html>row now the forward to resubmit.jsp is work , but forward to <jsp:forward page="/servlet/Insert"/>
is not work , why?
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
import javax.sql.*;
import pool.ConnectionPool;
public class Insert extends HttpServlet {
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps = null;
ConnectionPool connectionPool = null;
* We want to initialized the JDBC connections here
public void init()
String jdbcDriver = "com.mysql.jdbc.Driver";
String dbURL ="jdbc:mysql://localhost/survey?";
try
//instantiate the connection pool object by passing the
//jdbc driver, database URL, username, and password
connectionPool = new ConnectionPool(jdbcDriver, dbURL,
"root","mysql");
//specify the initial number of connections to establish
connectionPool.setInitialConnections(5);
//specify number of incremental connections to create if
//pool is exhausted of available connections
connectionPool.setIncrementalConnections(5);
//specify absolute maximum number of connections to create
connectionPool.setMaxConnections(20);
connectionPool.createPool(); //create the connection pool
catch(Exception e)
System.out.println("Error: " + e);
/** Destroys the servlet.
public void destroy() {
public void doGet(
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
}// end of DoGet
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
try {
//Get the incoming data parameters from the client
String name=req.getParameter("name");
String stuNumber=req.getParameter("stuNumber");
String gender=req.getParameter("gender");
String facultName=req.getParameter("facultyName");
String degree=req.getParameter("degree");
String year=req.getParameter("year");
String quesOne=req.getParameter("quesOne");
String quesTwo=req.getParameter("quesTwo");
String quesThree=req.getParameter("quesThree");
String quesFour=req.getParameter("quesFour");
String quesFive=req.getParameter("quesFive");
String quesSix=req.getParameter("quesSix");
String quesSeven=req.getParameter("quesSeven");
String quesEight=req.getParameter("quesEight");
String quesNine=req.getParameter("quesNine");
String quesTen=req.getParameter("quesTen");
String quesEleven=req.getParameter("quesEleven");
String quesTwelve=req.getParameter("quesTwelve");
String quesThirteen=req.getParameter("quesThirteen");
String quesFourteen=req.getParameter("quesFourteen");
String quesFifteen=req.getParameter("quesFifteen");
String quesSixteen=req.getParameter("quesSixteen");
String quesSeventeen=req.getParameter("quesSeventeen");
String quesEighteen=req.getParameter("quesNineteen");
String quesNineteen=req.getParameter("quesNineteen");
String quesTwenty=req.getParameter("quesTwenty");
String quesTwentyOne=req.getParameter("quesTwentyOne");
String ErrMsg="";
String found="";
HttpSession userSession = req.getSession(true);
HttpSession session=req.getSession();
for (int i=0; i<stuNumber.length(); i++){
char ch=stuNumber.charAt(i);
if (Character.isLetter(ch)){
found =found +ch;}
* check the empty fields
if (stuNumber.equals("") ||
((found.length()>=1 ))||
(stuNumber.length()!=10))
out.println("<html>");
out.println("<body bgcolor=\"#FFFFFF\">");
out.println("<center>");
out.println("<strong> Valid Studend number is require!<strong>");
out.println("</center>");
out.println("</body>");
out.println("</html>");
out.close();
Integer q1=0, q2=0, q3=0, q4=0, q5=0, q6=0, q7=0, q8=0,q9=0,q10=0;
Integer q11=0, q12=0, q13=0, q14=0, q15=0, q16=0, q17=0, q18=0, q19=0, q20=0,q21=0;
q1 = Integer.valueOf(quesOne);
q2 = Integer.valueOf(quesTwo);
q3 = Integer.valueOf(quesThree);
q4 = Integer.valueOf(quesFour);
q5 = Integer.valueOf(quesFive);
q6 = Integer.valueOf(quesSix);
q7 = Integer.valueOf(quesSeven);
q8 = Integer.valueOf(quesEight);
q9 = Integer.valueOf(quesNine);
q10 = Integer.valueOf(quesTen);
q11 = Integer.valueOf(quesEleven);
q12 = Integer.valueOf(quesTwelve);
q13 = Integer.valueOf(quesThirteen);
q14 = Integer.valueOf(quesFourteen);
q15 = Integer.valueOf(quesFifteen);
q16 = Integer.valueOf(quesSixteen);
q17 = Integer.valueOf(quesSeventeen);
q18 = Integer.valueOf(quesEighteen);
q19 = Integer.valueOf(quesNineteen);
q20 = Integer.valueOf(quesTwenty);
q21 = Integer.valueOf(quesTwentyOne);
Integer total=0;
total=q1+q2+q3+q4+q5+q6+q7+q8+q9+q10+q11+q12+q13+q14+q15+q16+q17+q18+q19+q20+q21;
/*if form is valid, catch the session*/
userSession.setAttribute("stuNumber",stuNumber );
userSession.setAttribute("quesOne",quesOne);
userSession.setAttribute("quesTwo",quesTwo);
userSession.setAttribute("quesThree",quesThree);
userSession.setAttribute("quesFour",quesFour);
userSession.setAttribute("quesFive",quesFive);
userSession.setAttribute("quesSix", quesSix);
userSession.setAttribute("quesSeven",quesSeven);
userSession.setAttribute("quesEight",quesEight);
userSession.setAttribute("quesNine",quesNine);
userSession.setAttribute("quesTen",quesTen);
userSession.setAttribute("quesTwelve", quesTwelve);
userSession.setAttribute("quesEleven", quesEleven);
userSession.setAttribute("quesThirteen", quesThirteen);
userSession.setAttribute("quesFourteen", quesFourteen);
userSession.setAttribute("quesFifteen", quesFifteen);
userSession.setAttribute("quesSixteen", quesSixteen);
userSession.setAttribute("quesSeventeen",quesSeventeen);
userSession.setAttribute("quesEighteen", quesEighteen);
userSession.setAttribute("quesNineteen",quesNineteen);
userSession.setAttribute("quesTwenty",quesTwenty);
userSession.setAttribute("quesTwentyOne",quesTwentyOne);
userSession.setAttribute("total",total);
RequestDispatcher disp;
disp = getServletContext().getRequestDispatcher("/confirmation.jsp");
disp.forward(req, res);
//get free connection from pool
conn =connectionPool.getConnection();
//select a database
// conn.setCatalog("survey");
/* add this part*/
stmt = conn.createStatement();
rs = stmt.executeQuery("SELECT* FROM survey where stuNumber='"+stuNumber+"'");
int count =0;//how many rows we can find.
while (rs.next()){
count++;
connectionPool.returnConnection(conn);
if(count<1){
conn.setAutoCommit(false);
String sql="insert into survey(name, stuNumber, gender,facultyName,degree, year, quesOne, quesTwo, quesThree, quesFour, quesFive, quesSix,quesSeven, quesEight, quesNine,quesTen,quesEleven, quesTwelve, quesThirteen, quesFourteen,quesFifteen, quesSixteen, quesSeventeen, quesEighteen, quesNineteen, quesTwenty, quesTwentyOne)";
sql+="value(?, ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
ps = conn.prepareStatement(sql);
stmt = conn.createStatement();
ps.setString(1, name);
ps.setString(2, stuNumber);
ps.setString(3, gender);
ps.setString(4, facultName);
ps.setString(5, degree);
ps.setString(6, year);
ps.setString(7, quesOne);
ps.setString(8, quesTwo);
ps.setString(9, quesThree);
ps.setString(10, quesFour);
ps.setString(11, quesFive);
ps.setString(12, quesSix);
ps.setString(13, quesSeven);
ps.setString(14, quesEight);
ps.setString(15, quesNine);
ps.setString(16, quesTen);
ps.setString(17, quesEleven);
ps.setString(18, quesTwelve);
ps.setString(19, quesThirteen);
ps.setString(20, quesFourteen);
ps.setString(21, quesFifteen);
ps.setString(22, quesSixteen);
ps.setString(23, quesSeventeen);
ps.setString(24, quesEighteen);
ps.setString(25, quesNineteen);
ps.setString(26, quesTwenty);
ps.setString(27, quesTwentyOne);
ps.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
connectionPool.returnConnection(conn);
/* doing the update*/
else{
conn.setAutoCommit(false);
String sql2 = "UPDATE survey set name=?";
sql2+= ", gender=?,facultyName=?,degree=?, year=?, quesOne=?, questwo=?, quesThree=?, quesFour=?, quesFive=?, quesSix=?,";
sql2+= "quesSeven=?,quesEight=?, quesNine=?, quesTen=?,quesEleven=?, quesTwelve=?, quesThirteen=?, quesFourteen=?";
sql2+=",quesFifteen=?, quesSixteen=?, quesSeventeen=?, quesEighteen=?, quesNineteen=?, quesTwenty=?, quesTwentyOne=?";
sql2+="WHERE stuNumber=?";
ps = conn.prepareStatement(sql2);
stmt = conn.createStatement();
ps.setString(1, name);
ps.setString(2, gender);
ps.setString(3, facultName);
ps.setString(4, degree);
ps.setString(5, year);
ps.setString(6, quesOne);
ps.setString(7, quesTwo);
ps.setString(8, quesThree);
ps.setString(9, quesFour);
ps.setString(10, quesFive);
ps.setString(11, quesSix);
ps.setString(12, quesSeven);
ps.setString(13, quesEight);
ps.setString(14, quesNine);
ps.setString(15, quesTen);
ps.setString(16, quesEleven);
ps.setString(17, quesTwelve);
ps.setString(18, quesThirteen);
ps.setString(19, quesFourteen);
ps.setString(20, quesFifteen);
ps.setString(21, quesSixteen);
ps.setString(22, quesSeventeen);
ps.setString(23, quesEighteen);
ps.setString(24, quesNineteen);
ps.setString(25, quesTwenty);
ps.setString(26, quesTwentyOne);
ps.setString(27, stuNumber);
ps.executeUpdate();
conn.commit();
conn.setAutoCommit(true);
connectionPool.returnConnection(conn);
}catch (SQLException e) {
throw new ServletException(e);
finally {
try {
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(ps != null)
ps.close();
if(conn != null)
conn.close();
connectionPool.returnConnection(conn);
} catch (SQLException e) {}
} // end doPost
public String getServletInfo()
return "A Simple Servlet";
}// end of ContrInsertThe way to do this with a JSP is use an HTML Form tag to pass all the information on to a new page, and save the new info while creating this new page
-
Retrieve POST variables just like in a normal HTTP forms
Hi All :D
Can anyone tell me how to retrieve POST variables just like
in a normal HTTP form?
I have 2 flex applications. One will send the POST variables
and I would like the other to retrieve
these variables. How to implement this?
Thanks :D"JuggerOgre" <[email protected]> wrote in
message
news:g92bce$kgf$[email protected]..
> Hi All :D
>
> Can anyone tell me how to retrieve POST variables just
like in a normal
> HTTP
> form?
> I have 2 flex applications. One will send the POST
variables and I would
> like
> the other to retrieve
> these variables. How to implement this?
Flex is a client side application. You could send them from
one client and
then request them from the other client, or you could use
something like
BlazeDS to "push" the information.
HTH;
Amy -
Parameters are corrupted in Servlet Post method Why
Arguement from Client is
"This is my Test"
But in the servlet the output is
STRING BUFFER�φ ♣t ♫This is a Test
Applet Code is
URL url =new URL("http://localhost:8080/portal/servlet/com.kbs.framework.client.gui.ReportServlet");
HttpURLConnection servletConnection = (HttpURLConnection)url.openConnection();
servletConnection.setDoInput(true);
servletConnection.setDoOutput(true);
servletConnection.setUseCaches(false);
servletConnection.setDefaultUseCaches(false);
servletConnection.setRequestMethod("POST");
servletConnection.setRequestProperty("Content-type","application/octet-stream");
servletConnection.addRequestProperty("COMMAND" ,"test");
servletConnection.setRequestProperty("COMMAND" ,"tes");
ObjectOutputStream outStream =
new ObjectOutputStream(servletConnection.getOutputStream());
System.out.println("CLIENT COMMAND" + command.trim());
outStream.writeObject("This is a Test");
outStream.flush();
outStream.close();
Servlet Post method
try
System.out.println("**********************************************");
System.out.println("COMMAND IS" + request.getParameter("COMMAND"));
InputStream requestInputStream = request.getInputStream();
System.out.println("REQUEST INPUT STREAM" + requestInputStream);
InputStreamReader isr = new InputStreamReader(requestInputStream);
System.out.println("REQUEST INPUT STREAM ReaDER" + isr);
BufferedReader br = new BufferedReader(isr);
System.out.println("BUFFERED READER" + br);
String line = "";
StringBuffer sb= new StringBuffer();
while ((line = br.readLine()) != null)
sb.append(line);
br.close();
System.out.println("STRING BUFFER" + sb.toString()); // display the input StreamMy guess is that you wrote the String "THIS IS A TEST" as a serializable object but tried to read it as character text.
ObjectOutputStream outStream =
new ObjectOutputStream(servletConnection.getOutputStream());
outStream.writeObject("This is a Test");Serializing an Object stores extra data so that the Object can re-instantiated and it is this extra data that you are seeing. -
Hi,
I have set up the following on a solaris 2.8 box
a) A custom application packaged as a jar file...
b) Set up the initial environment for my application using weblogicenv.sh
c) The first request for the servlet is satified, in the sense that I am able
to get some data out from my servlet..
d) The second page posts some variables, which is not being read by my application
and hence I am getting a HTTP:404 (file not found)..
e) I check in the access.log the above error is noticed.
I have read all the documentation realting to the weblogic app server properties
file...
I believe I am missing out on some rewrite rules in config files...But don't
know which ones..Any ideas/suggestion ...
TIA
Praveenhai,,,
u didnt mention which web server u r using... -
I have a JSP page which recieves a number of arguments.
One of those arguments in a desination URL. The JSP page picks this up and then uses a response.sendRedirect(URL) call to forward the user to this page.
Is there anyway of passing these other arguments across to this destination page as hidden variables.
I dont want to append these variables to the existing URL as they should remain hidden.
What other methods can I use for these variables to accompany the sendRedirect call or is there a different approach thats required for this case ??
Thanks in advance,
RichardYou can try this. It works.
out.println("<html>");
out.println("<head>");
out.println("<title></title>");
out.println("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">");
out.println("</head>");
out.println("<body bgcolor=\"#FFFFFF\" text=\"#000000\" onLoad=\"javascript:document.forms[0].submit();\">");
out.println("<form name=\"formulario\" method=\"post\" action=\"http://PutHereTheURLOfsendRedirect\">");
// Put here your hidden variables.
out.println("<input type=\"hidden\" name=\"hiddenField1\" value=\"hiddenvalue1\">");
out.println("<input type=\"hidden\" name=\"hiddenField2\" value=\"hiddenvalue2\">");
out.println("</form>");
out.println("</body>");
out.println("</html>"); -
Posting variables from Captivate 5
Dear gurus,
I would like to be able to post quiz and user variable data from Captivate 5. I notice that the Cap. 5 has Javascript functionality but is there any way of referencing a lesson's variable data so that it can be posted out of Captivate?
My goal is to post data to a server script which will then route the data to a database. I realise there is the new alternate results feature but I can't use php in my workplace. I also can't use an LMS for the recording of data.
Any help would be greatly appreciated.
Best wishes,
Mister GeeSo I keep working with it, trying to get the data from the POST. I've tried using a very rudimentary method of checking to see if I'm able to get the variables, but for some reason, I'm not able to. Here's a snippet of what I'm doing just to see if I'm getting the values. Once I'm able to write the values to the text file, I'll be able to move forward.
<%
dim fs,f
set fs=Server.CreateObject("Scripting.FileSystemObject")
dataString = request.form("dataString")
CompanyName = request.form("CompanyName")
DepartmentName = request.form("DepartmentName")
CourseName = request.Form("CourseName")
Filename = request.Form("Filename")
Filedata = request.Form("Filedata")
If NOT fs.FolderExists("D:\Hac_userdata\QWDweb\elearning\CaptivateResults\") then
fs.CreateFolder("D:\Hac_userdata\QWDweb\elearning\CaptivateResults\")
Else
End If
set f=fs.OpenTextFile("D:\Hac_userdata\QWDweb\elearning\CaptivateResults\test.txt", 8, true)
f.WriteLine("( " & DepartmentName & " )" & " " & now())
f.close
set f=nothing
Set fs=Nothing
%> -
CharConversionException during Servlet Post method - Need fix.
XML request message using HTTP POST is received by the Servlet interface.
While we are reading and trying to parse the InputStreamObject, we are getting the following error message.
doPost java.io.CharConversionException: Characters larger than 4 bytes are not supported: byte 0x8e implies a length of more than 4 bytes
It looks like we are receiving some invalid Non-ASCII characters in the XML message.
The above error is thrown intermittently.
Whenever we have this CharConversionException, the servlet gets corrupted and it impacts few good xml messages that follows after the error.
I need to know the following:
1. How to fix this exception and skip the bad message?
2. Is it possible to log the entire xml message in the catch block, whenever we have this exception?
NOTE: we tried different ways, not able to print the xml message, as the inputstream seems to be closed/null, when it reaches the catch block.
Tried the below code , but the servlet process/thread hungs and throws the below error:
Thread "WebContainer : 3" (00000028) has been active for 667781 milliseconds and may be hung. There is/are 1 thread(s) in total in the server that may be hung.
Below is the code snippet:
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/xml");
request.setCharacterEncoding("ISO-8859-1");
OutputStream out = response.getOutputStream();
InputStream inputStream=null;
InputStream inputStreamTemp=null;
try {
// Create a new file upload handler
ServletFileUpload upload = new ServletFileUpload();
// Parse the request
FileItemIterator iter = null;
iter = upload.getItemIterator(request);
while (iter.hasNext()) {
FileItemStream item = iter.next();
String name = item.getFieldName();
inputStream = item.openStream();
inputStreamTemp=inputStream;
// we are trying to process the input stream
processXml(inputStream);
catch(CharConversionException charConversionException){
this.logger.error(charConversionException);
if(inputStreamTemp !=null){
logSlurp(inputStreamTemp,logger);
private static void logSlurp(InputStream in, Log logger) throws IOException {
StringBuffer out = new StringBuffer();
byte[] b = new byte[in.available()];
for (int n; (n = in.read(b)) != -1;) {
out.append(new String(b, 0, n));
if (logger.isInfoEnabled()) {
logger.info(out.toString());
Need any help to fix the issue we are facing? Issue of either fixing/overcoming the actual exception and printing out the entire xml message(bad one) in ours log
during the catch block.
Thanks a lot.Which line is the exception coming from?
It seems that your content type is UTF-8, even though you're sending LATIN-1 data.
Also, your "inputStreamTemp" is a redundant variable. -
Hi,
I am looking for a solution for following problem.
Step 1) Browser calls Servlet 1
Step2) Servlet 1 does a post to Servlet 2
i require that servlet 2 response to directly go to the browser has it is a HTML page with images.
Could any one please suggest me a solution for this.does servlet1 really have to do a post? It seems to me like you want to do a forward in stead. You can do that like this:
RequestDispatcher rd = request.getRequestDispatcher("/Servlet2");
rd.forward(request, response);
return;A forward will transfer control to the servlet (or JSP) you forward to while keeping the current request and response as they are. This means that any parameters submitted to Servlet1 will also be available in Servlet2.
i require that servlet 2 response to directly go to the browser has it is a HTML page with imagesI don't understand what you are asking here... you want to output HTML to the browser from within Servlet2? -
How to send a document in net.HTTP.request as a POST variable?
I have read and reread the doc on net.HTTP.request, and it says I can pass an argument of oRequest, but I have not succeeded at passing in the current document, which is what I want to do.
I've tried app.activeDocs[0], or encoding that to a string, but though it makes the call without error, nothing is sent.
Should oRequest be simply a document, or a variable made up of name-value pairs? How do we send multiple parameters to a POST otherwise?
I've succeeded fine with calling using GET, but when I tried to pass the document as a GET variable, I got nothing either.
I'm sending to a LiveCycle REST end point so either POST or GET is fine.
Thanks!POSTing the current document is straightforward *provided* your script is running outside the document context (i.e. in the console or a folder-level script). There's no access from doc-level scripts for obvious reasons.
For example, putting this in the JS console will POST the current file to a URL:
Net.HTTP.request({
cVerb:'POST',
cURL: 'http://localhost/submit.php',
oRequest: Collab.documentToStream(this),
oHandler: {
response: function (msg, uri, err) {
if (err!=undefined) app.alert(msg);
Your problem with talking to a vanilla webservice is that you cannot send the RFC1867 delimeters (i.e. form a "multipart/form-data" request) as the ReadStream object doesn't have a concatenation method in the Acrobat JSAPI. That's also how you would usually prepend other form fields, but if you're careful with your server-side coding you can send those as GET parameters in cURL. Normally you'd be polite and pass a Context-Type header in the aHeaders array - it won't matter to the transmission process but will allow your webservice to predict what the heck it's been sent.
Your webservice will then have to read the raw data. In PHP for example, you won't get anything in the $_FILES global but you can grab the PDF by reading everything from the input buffer, with the line:
$pdf = file_get_contents("php://input");
If that line was in the server script that the above JS code was aimed at, the variable $pdf will contain an exact binary copy of the currently-open document. -
Forwarding from servlet in web app...
I'm having a problem forwarding to a page within a web application. Basically if I do:
getServletContext().getRequestDispatcher("/login.htm").forward(request,response);
then the page isn't found as the forward doesn't put the web application context into the URL. I can work round this by using:
request.getContextPath()
and then building up the path with the web application in it.
This becomes a real pain too with static HTML pages. If the pages have links in them which are absolute, again the web application context is not prefixed.
Am I missing something here? I was under the impression that the deployment of web applications was supposed to be transparant to the components within them.
Any help would be appreciated. I'm running on WLS 6 on W2K.
Cheers,
Andy
Andy,
I'm haivng the same problem! I'm working with getting Jive (the open-source
discussion board product) to work with WLS. This software is full of
response.sendRedirect calls that are relative. These all fail with WLS 6.
Jeff Mathers
"Andy Winskill" <[email protected]> wrote in message
news:[email protected]...
>
> I should follow the flow of my servlet better.....
>
> The main problem is with request.sendRedirect not working with a relative
URL. Forwarding to an absolute URL in a web app works fine. However,
absolute links in a HTML page are absolute with respect to the server and
not the web application.
>
> Cheers,
> Andy
>
> "Andy Winskill" <[email protected]> wrote:
> >
> >I'm having a problem forwarding to a page within a web application.
Basically if I do:
> >
>
>getServletContext().getRequestDispatcher("/login.htm").forward(request,resp
onse);
> >
> >then the page isn't found as the forward doesn't put the web application
context into the URL. I can work round this by using:
> >
> >request.getContextPath()
> >
> >and then building up the path with the web application in it.
> >
> >This becomes a real pain too with static HTML pages. If the pages have
links in them which are absolute, again the web application context is not
prefixed.
> >
> >Am I missing something here? I was under the impression that the
deployment of web applications was supposed to be transparant to the
components within them.
> >
> >Any help would be appreciated. I'm running on WLS 6 on W2K.
> >
> >Cheers,
> >Andy
>
-
This might be a dumb question, but I'll ask it anyway...
I have methods in my servlet to handle registration, specifically creating address, customer and order objects.
All the information needed for creating my objects is coming from the registration form.
Right now if I were to call the createAddress() method, I have to pass the request object.... createAddress(request);
Would it be "thread safe" to make an instance variable of the request and refer to it using getters/setters? Or would it be wiser (and best practice) to make instance variables for the request attributes (like firstName, lastName, etc.)? Or am I way off and shouldn't be doing any of the above?
Thanks for the help.GB_java_guy wrote:
To answer you question, I think it's different, from what I've read, because request attributes are supposed to be thread safe and I'd be using the request attributes instead of the request object.You said something about "making instance variables for the request attributes." I don't know what you mean by that, but if it's instance variable in the servlet class, don't do it.
I have no clue what you mean by "request attirbutes intead of request object."
So are you saying I should just use the request object and pass that to my methods instead? In general, yes. In some cases you may want to pass individual pieces of it--e.g. if there's a method that doesn't need to know or care about the fact that you're operating in a servlet context, and just needs a couple values to do its job. -
Im using tomcat 4.06 and i have some problems with servlets and forwarding:
This is my servlet:
import java.io.PrintWriter;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
public class NTenant extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String email = request.getParameter("tenant");
//insert new tenant into database.
System.out.println("Redirigiendo");
ServletContext sc = getServletConfig().getServletContext();
RequestDispatcher rdNext = sc.getRequestDispatcher("/tenantForm.html");
rdNext.forward(request, response);
System.out.println("Redirigido");
I get this error:
type Status report
message Servlet invoker is currently unavailable
description The requested service (Servlet invoker is currently unavailable) is not currently available.
This is my dir structure:
webapps\form\NewTenant.html
webapps\form\tenantForm.html
webapps\form\WEB-INF\web.xml
webapps\form\WEB-INF\classes\NTenant.class
webapps\form\WEB-INF\classes\TenantServlet.class
The problem is that i cannot find my html, what must i write here? sc.getRequestDispatcher("/tenantForm.html"); <-----
Thank you very muchI heve tried with "../tenantForm.html"
java.lang.IllegalArgumentException: Path ../tenantForm.html does not start with a "/" character
at org.apache.catalina.core.ApplicationContext.getRequestDispatcher(ApplicationContext.java:572)
at org.apache.catalina.core.ApplicationContextFacade.getRequestDispatcher(ApplicationContextFacade.java:174)
at NTenant.doPost(NTenant.java:19)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
Now Im trying with:
RequestDispatcher rdNext = sc.getRequestDispatcher "/../tenantForm.html");
And I got:
type Exception report
message Internal Server Error
description The server encountered an internal error (Internal Server Error) that prevented it from fulfilling this request.
exception
java.lang.NullPointerException
at NTenant.doPost(NTenant.java:20)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.servlets.InvokerServlet.serveRequest(InvokerServlet.java:465)
at org.apache.catalina.servlets.InvokerServlet.doPost(InvokerServlet.java:216)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
at java.lang.Thread.run(Thread.java:536)
Any other idea?
Maybe you are looking for
-
How to connect/move film from a Canon videocamera Legira HF R 106 to the iPad 3. I don't find USB or port to card on iPad???
-
Reverse engineering a synonym in ODI 11G .
i reverse engineered a synonym in oDI 11g using the RKM oracle but i 'm unable to get the column structure. So how to reverse enginer a synonym in ODI 11g ??
-
Uunable to complete upload to ftp host
Please guys....need to fix this issue asap. This is the worst issue in Muse and it needs to direct to Adobe to fix it right away.
-
Recomendations for you doesn't work
quick link on main page of iTunes doesn't work. I've tried everything and I can't get the link to work. It worked fine for years and then it slowly stopped sending "Recommendations for you" would time out and I would remain on main iTunes web page
-
Missing shortcut in Mac osx 10.8.2
Before I was able to browse all my open images in photoshop by using the shortcut F3, now the same shortcut places all the images on top of each other. Does anyone know if there is a short for what I want to do? I don't know if this really is an issu