Solved

Sending a Java Object to JSP page

Posted on 2004-04-28
4
612 Views
Last Modified: 2010-05-18
Hello fellow experts,

Hi I want to send a Java String to a jsp page and I want the jsp page to send a vector back to the java program.

half is done...I think...

in my java class
URL url = new URL(strPath);
         HttpURLConnection conn = (HttpURLConnection)url.openConnection();
         conn.setDoOutput(true);
         conn.setRequestMethod("POST");
         conn.setRequestProperty("Content-type", "application/octet-stream");
         OutputStream os = conn.getOutputStream();
         ObjectOutputStream out = new ObjectOutputStream(os);
         
     
         out.writeObject(strXMLParams);
         out.flush();
         out.close();

I just need the code to receive and then to send back an object to the java the java code to receive the vector would be nice too
thanks
Ghost
0
Comment
Question by:copyPasteGhost
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 13

Author Comment

by:copyPasteGhost
ID: 10943104
this question is seeming to overlap into this question

http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_20968074.html

anyone know what to do?
Ghost
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10945439
Have you tried request.setAttribute() and request.getAttribute()??? they shd be able to get your job done..!!
0
 
LVL 19

Expert Comment

by:Kuldeepchaturvedi
ID: 10945483
Or if you are adamant doing it above described way then

in your jsp.
ObjectInputStream oip = new ObjectInputStream(request.getInputStream());
YourObj obj = (YourObj)(oip.readObject());


This stuff gonna throw a lot of exceptions so a try catch block is on the card obviously..:-)
0
 
LVL 27

Accepted Solution

by:
rrz earned 250 total points
ID: 10945588
I am not sure if I understand your requirements. But I did write the following two pages(located in same directory).      rrz  

------------sender.jsp----------------------------------------
<%@ page import="java.util.*,java.net.*,java.io.*" %>
<%  
         Vector vSend = new Vector();
         vSend.add("one");
         vSend.add("two");
         vSend.add("three");
         String urlStr = request.getRequestURL().toString();
         URL url = new URL(urlStr.substring(0,urlStr.lastIndexOf("/")+1) + "bouncer.jsp");
         HttpURLConnection conn = (HttpURLConnection)url.openConnection();
         conn.setDoOutput(true);
         conn.setDoInput(true);
         conn.setRequestMethod("POST");
         conn.setRequestProperty("Content-type", "application/octet-stream");
         ObjectOutputStream oos = new ObjectOutputStream(conn.getOutputStream());
         oos.writeObject(vSend);
         oos.flush();
         ObjectInputStream in = new ObjectInputStream(conn.getInputStream());
         Vector vBack = (Vector)in.readObject();
         in.close();
         oos.close();
%>
vBack=<%=vBack%>

-------------------------------bouncer.jsp---------------------------------------------
<%@ page import="java.net.*,java.io.*" %>
<%
         ObjectInputStream ois = new ObjectInputStream(request.getInputStream());
         ObjectOutputStream oos = new ObjectOutputStream(response.getOutputStream());
         oos.writeObject(ois.readObject());
         oos.flush();
         ois.close();
         oos.close();
%>
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fisheye tool 2 122
org.apache.jasper.JasperException: using jstl in jsp embedded jetty 13 708
spring example non maven 4 98
login jsp example 24 85
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
This article discusses how to implement server side field validation and display customized error messages to the client.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question