Solved

Sending a Java Object to JSP page

Posted on 2004-04-28
4
613 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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article will help to fix the below error for MS Exchange server 2010 I. Out Of office not working II. Certificate error "name on the security certificate is invalid or does not match the name of the site" III. Make Internal URLs and External…
This article outlines some of the reasons why an email message gets flagged as spam on a recipient's end.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

726 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