Getting Data to a Servlet
Hi, I someone with little experience with Java EE programming.
I have a simple web application consisting of jsp and servlets. A servlet generates an image based on a string which is displayed on a jsp page along with a form containing a text input and a drop down list to select a number from 0-9. I also have a seperate java program which generates the string and then requires the data entered in the form on the webpage.
My difficulty is how to get the data to and from the java program and servlet. JMS was recommended to me for this purpose and I've been investigating the Message-Driven bean example from the Java EE 5 Tutorial [The Java EE Message Bean|http://java.sun.com/javaee/5/docs/tutorial/doc/bnbpk.html] . I have adapted the java program to be part of the application client so that I can send the strings needed in the webapp straight to the message bean and grouped these two and the webapp as part of an Enterprise Application.
I was wondering how to get the information form the message bean to the servlet in the web application?
Also suggestions as to how to get the form information submitted in the jsp pages back to the java program (this bit maybe should be in a different forum?).
Thanks for your time,
atreides7887
Edited by: atreides7887 on Apr 9, 2008 2:54 AM
this is the code inside my servlet
Similar Messages
-
How can i get an Applet transfer data to a servlet like a Form does?
it is clear that URL class provides way to connect to remote web resource. and furthermore i am trying to make an applet perform like a Form in html to send user data to a servlet. i may adhere a long name-value string to url sent by applet but this is not a good way to hide information like hidden variables. Is there any class in J2SE package that i can wrap those Form data and send them in the way Form does...?
cheers!Double posted
http://forum.java.sun.com/thread.jspa?threadID=578770&messageID=2913924#2913924
In your other post:
but i just don't want to build a string with serlet name followed by many NV pairs tthis is a GET request:
myURL?name=value&name=value
To use a POST
http://javaalmanac.com/egs/java.net/Post.html
This still requires you to make a VP string that you write to an outputstream of the
URLConnection. There is no other way to do this unless in an applet. -
How get data in servlet from selected recotrd
I want set on my UIX site new button which after click will invoke servlet. In this servlet, I need a method which get data from selected record and write it to file. I have two questions. What kind of button I have to use to send data from selected record on my UIX site and how can I get selected data in servlet (I don't know a method - request.getParameter("column_name") doesn't work) It's very important for me. Please anyone response ?
If you are using ADF you can how which row were selected using the following code
tableClients.setRowIndex(
Integer.parseInt(
(String)
tableClients.getSelectionState().getKeySet().iterator().next()));
client = (Client) tableClients.getRowData();
assuming that the <af:table> have a binding to a managed bean and that it have an "selection" facet and you include your command button in these facet
to write to a file check java.sun.com and look for BufferedWriter or BufferedOutputStream
Atilio -
Error :Unable to retrieve data from iHTML servlet for Request2 request
I open bqyfile to use HTML in workspace.
When I export report to excel in IR report.
Then I press "back" button I get error"Unable to retrieve data from iHTML servlet for Request2 request "
And I can not open any bqyfiles in workspace.
Anybody gat the same question? Thanks~Hi,
This link will be helpful, the changes is made in the TCP/IP parameter in the registry editor of Windwos machine. I tried the 32 bit setting for my 64 bit machine (DWORD..) and it worked fine for me..
http://timtows-hyperion-blog.blogspot.com/2007/12/essbase-api-error-fix-geeky.html
Hope this helps.. -
Getting session information in servlet?
In Apache SOAP, org.apache.soap.rpc.SOAPContext can be used as a parameter to get at session data in your servlet. The JDeveloper web services publishing wizard won't expose a method with this parameter, saying that the XML Schema mapping and/or serializer is not specified. Is there an OC4J equivalent to get at session information?
Hi.
Most definitely possible. A few months ago I coded something very similar - jsp
form, submit to a servlet. I needed to get and set session info in both the
servlet and jsp. The code was very basic (ie no tricks involved) and worked
well. FWIW both my servlet and jsp were in the same webapp.
Good luck,
Michael
PeterH wrote:
Howdy.
re meant something else
That's what I'm trying to figure out. :>
re what do I mean by...
I have one jsp page, that has a an html form on it with elements that get
passed to a servlet through a submit button on the form. I would like to be
able to get information about the session from within the servlet. Is that
possible?
Let me know if I'm not explaining myself properly and you need more info.
I'm relatively new to this stuff. But I'm learning! :>>>>
Thanks for your reply.
<[email protected]> wrote in message news:[email protected]..
Hrm. Whoever told you this probably meant something else. What do you mean
by a 'servlet being called from a jsp' ?
PeterH <!REMOVEBeforeSending![email protected]> wrote:
I was told today when using a servlet within a web app (being called
from a
jsp), you do not have access to the session object. Is that true?Short of
passing session attributes via the servlet call, how can you access the
session information?
Thanks for any ideas.--
Dimitri
Michael Young
Developer Relations Engineer
BEA Support -
To get date of second sunday in march and first sunday in november of year
Hi all,
i need some java code to get date of second sunday in march and first sunday in november of every year.
this is very urgent
plz help
thanks in advance
jhansiHi,
Check below links for UDF's.
UDF
http://flickr.com/photos/8764045@N06/
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/be05e290-0201-0010-e997-b6e55f9548dd
Example 1
http://www.flickr.com/photo_zoom.gne?id=544183191&size=o
http://www.flickr.com/photo_zoom.gne?id=544183195&size=o
http://www.flickr.com/photo_zoom.gne?id=544183225&size=o
http://www.flickr.com/photo_zoom.gne?id=544183233&size=o
Example 2
http://www.flickr.com/photo_zoom.gne?id=545133789&size=o
http://www.flickr.com/photo_zoom.gne?id=545133791&size=o
http://www.flickr.com/photo_zoom.gne?id=545133801&size=o
http://www.flickr.com/photo_zoom.gne?id=545133807&size=o
http://www.flickr.com/photo_zoom.gne?id=545133811&size=o
http://www.flickr.com/photo_zoom.gne?id=545138911&size=o
http://www.flickr.com/photo_zoom.gne?id=545138913&size=o
http://www.flickr.com/photo_zoom.gne?id=545138915&size=o
http://www.flickr.com/photo_zoom.gne?id=545138917&size=o
http://www.flickr.com/photo_zoom.gne?id=545138947&size=o
http://www.flickr.com/photo_zoom.gne?id=545138951&size=o
http://www.flickr.com/photo_zoom.gne?id=545005958&size=o
Example 3
http://www.flickr.com/photo_zoom.gne?id=549186611&size=o
http://www.flickr.com/photo_zoom.gne?id=549186651&size=o
http://java.sun.com/j2se/1.5.0/docs/api/
/people/krishna.moorthyp/blog/2006/07/29/documentation-html-editor-in-xi
/people/sap.user72/blog/2006/02/06/xi-mapping-tool-exports
http://help.sap.com/saphelp_nw04/helpdata/en/43/c4cdfc334824478090739c04c4a249/content.htm
http://help.sap.com/saphelp_nw04/helpdata/en/22/e127f28b572243b4324879c6bf05a0/content.htm
/people/stefan.grube/blog/2005/12/30/test-user-defined-functions-for-the-xi-graphical-mapping-tool-in-developer-studio
http://help.sap.com/bp_bpmv130/Documentation/Operation/MappingXI30.pdf
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d046c490-0201-0010-84b6-9df523cbca31
Regards,
Phani
Reward Points if Helpful -
I am converting a servlet based application to struts framework.I have a screen which gets data from 7 tables.I cannot use a stored procedure so has to manage using SQL queries.I thought i will query each table and set it to my struts form.The screen has lot of drop down boxes .
I have heard of composite design pattern .Please let me know the best way to query the tables.Here are the queries.
Select a.proj_id , a.proj_nm
From stn_proj_et a, stn_proj b
Where a.proj_id = b.proj_id
And a.sftwr_id = 24
And b.stn_id = 56602;
Select round(utm_x,3) utm_x, round(utm_y,3) utm_y, stn_id
From stn_loc_hist
Where stn_id ='56602'
And cur_use_cd = 1
select data_tp_cd
from data_coll_summ
where stn_id ='56002'
And rownum < 2;
select lat_no,long_no,pnt_loc_dsc,srce_id,mthd_dtrmn_cd,ctrl_dtm_cd
from stn_et
where stn_id = '56002';
select
distinct sjr_utils.getcatalogvalue(mthd_dtrmn_cd)
from stn_et;
select
distinct sjr_utils.getcatalogvalue(ctrl_dtm_cd)
from stn_et;
select distinct PROJ_NM from stn_proj_et where sftwr_id=24;
Select a.stn_alias_nm stn_alias_nm, b.alias_orgn_nm alias_orgn_nm
From stn_alias_nm a, alias_orgn_et b
Where a.alias_orgn_id = b.alias_orgn_id
And b.alias_orgn_tp = 0
And stn_id = '56002';adithiananya wrote:
I am converting a servlet based application to struts framework.How well do you know Struts?
I have a screen which gets data from 7 tables.I cannot use a stored procedure so has to manage using SQL queries.I thought i will query each table and set it to my struts form.The screen has lot of drop down boxes .You don't need a stored procedure to query a database.
I have heard of composite design pattern .This ain't it.
Please let me know the best way to query the tables.Here are the queries.
Select a.proj_id , a.proj_nm
From stn_proj_et a, stn_proj b
Where a.proj_id = b.proj_id
And a.sftwr_id = 24
And b.stn_id = 56602;What are those hard-wired magic numbers in the WHERE clause?
>
Select round(utm_x,3) utm_x, round(utm_y,3) utm_y, stn_id
From stn_loc_hist
Where stn_id ='56602'
And cur_use_cd = 1What are those hard-wired magic numbers in the WHERE clause?
>
select data_tp_cd
from data_coll_summ
where stn_id ='56002'
And rownum < 2;What are those hard-wired magic numbers in the WHERE clause?
>
select lat_no,long_no,pnt_loc_dsc,srce_id,mthd_dtrmn_cd,ctrl_dtm_cd
from stn_et
where stn_id = '56002';
select
distinct sjr_utils.getcatalogvalue(mthd_dtrmn_cd)
from stn_et;
select
distinct sjr_utils.getcatalogvalue(ctrl_dtm_cd)
from stn_et;
select distinct PROJ_NM from stn_proj_et where sftwr_id=24;What are those hard-wired magic numbers in the WHERE clause?
Select a.stn_alias_nm stn_alias_nm, b.alias_orgn_nm alias_orgn_nm
From stn_alias_nm a, alias_orgn_et b
Where a.alias_orgn_id = b.alias_orgn_id
And b.alias_orgn_tp = 0
And stn_id = '56002';What are those hard-wired magic numbers in the WHERE clause?
Do you really want to execute different requests given input from the users? (e.g., enter a value in a text box and see the drop down list boxes change)
% -
!!! Storing and Getting data from HashMap !!!
Hi ,
I have got a doubt if this is possible .. Please let me know if this can be implemented ..
I have a Process1 running which stores data into HashMap one by one from the Users.
Eg:
Key Object
1 ---> Karthik
2 ---> Raaghav
3 ---> Srikanth
and so on ..
Now what i internally do is i will wait for 5 min Duration (Session TimeOut).Once it is Over 5 min I will delete it from HashMap and Store it in a file ..
Iam also using WebServer Eg:Iplanet .
Now when i Shut down Iplanet all the data in the HashMap is Lost .
My Requirement is to write another Process2 which will be invoked as soon as Iplanet is ShutDown and This process has to read the data from HashMap which is not Timed out .And write it into the File ..
Q1)Please Let me know if this is can be Done ..
Task Done :
Process1 is already existing
Doubts :
Q2)If we write a Process2 will it spawn another VM or it will take the same VM that of the Process1.
Becos if it spawns another VM then I will not be able to get the data from HashMap of the Process1..
Thanks in Advance,
[email protected]Thank You for the ..
But my prblm is that the Process1 is already Existing which reads and writes in to HashMap ( Not a Servlets) ..Its a Pure Java Code ..
And Now the requirement is another Process2 lets say which is put in thread (running in background )which gets the data from the HashMap of the Process1 or in other words Use the Same HashMap and not a different One ...
Process1 ------------------>HashMap
(write.java) (writes data ) /\
|
|
|(get Data)
|
|
|
Process2
I hope iam clear with my requirement ..
If Any further explanation Required Iam perpared to give ..Please let me know
thanks in advance .. -
I am creating an applet to draw graphs.
I have only made standalone applets before.
My data will come from a database.
The user will have the data selected for them, when they select the applet page, the data to be drawn will already have been selected.
i.e. I only need to give data across in the initialisation stage of the applet.
What is the standard way to get data into an applet?
By a giving a file path, by direct contact with the DB, with direct contact with another servlet or by giving the data in the HTML page the Applet is contained in.
(The data will come from the same server as the applet)
Maybe somone can point me to a tutorial on this?I am currently developing some graph applets, too. At first I implemented direct database access via JDBC, but found out, that this ain't suitable, because you can get in serious trouble with customers who don't want to open database tcp ports in their internal firewall system which - from a security point of view - is a good decision.
So I gathered information about other methods to get data across the network. RMI needs own ports just like JDBC. Direct access to port 80 would be a good, so one could use Java's network capabilities. But this needs lots of coding on both ends (server and client-applet) and so takes time and is error prone.
Using SOAP leads to fat applets and so I gave XML-RPC a try. In my case I have an XML-RPC server written in PHP (using the PEAR module see: http://pear.php.net ) and in my applet I use the XML-RPC library from the Apache Group (see: http://ws.apache.org/xmlrpc/ ). This works just fine!
Pros:
- small library code in applet (less than 200 KB)
- only needs one network port. standard is 80 (http) which is almost everywhere available
- applet code is independent from server code and architecture, as almost every language has some XML-RPC module (other than RMI being a Java-only solution)
- free of charge & open source
- reliable
Cons:
- based on XML it can slow down things a bit when lots of data has to be sent over a slow network link - but that's more of a general problem in network application development
- other than SOAP/RMI you can not transmit/access whole objects but only data of primitive types (int, boolean, string, ..), so you have to wrap and unwrap your data
By now I am very pleased with the decision I made earlier this year. :) -
Binary data in a servlet's doGet method?
Hi,
How to write binary data in a servlet's doGet method? Anyone, please help.Use POST instead of GET to transfer binary data. For GET, you can only append the data in the QUERY_STRING and its length is very limited. so better use POST.
-
How to pass submitted Data from a servlet to EJB Session Bean in JPA
How to pass Data User submitted Data from a servlet to EJB Session Bean when using JPA :
Hi ,
I have a jsp page in which the user fills up the Data and submits it to the servlet :
Inside servlets i am getting all the parameters and setting it to the Entity Class .
Sample Entity class is shown below :
@Entity
public class Employee {
@Id private int id;
private String name;
public Employee() {}
public Employee(int id) { this.id = id; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getName() { return name; }
public void setName(String name) { this.name = name; }
}After calling setters of my Entity Class .
I am using JNDI lookup to call my session Bean method and pass this Entity class to the session Bean to persist data
Please let me know what will be the right approach :
1. Passing parameters whole as a Entity Class
that is
public void insertData(Employee emp)
}Or
2. public void insertData(String Name , int ID)
}they are both right as they both work. Easy huh?
You might argue that if you have to set a lot of fields, use the entity as otherwise you get a method with a gigantic amount of parameters. -
How to get Date and time of the server?
Hi, How can we get the date and time of the server while submitting a form using JSP? i.e I need the date and time , when the user is submittig a registration.
UmaUpon receiving your data in your servlet, you can do the following to get the date,
Calendar calendar = Calendar.getInstance();
int dd = calendar.get(Calendar.DAY_OF_MONTH);
int mm = calendar.get(Calendar.MONTH) + 1;
int yyyy = calendar.get(Calendar.YEAR);
String dd_mm_yyyy = dd + "/" + mm + "/" + yyyy;
To get the time, simply take a look at the Calendar API to get the corresponding field. -
Problem-Writing datas to a Servlet thro' URLConnection class
Hi,
Iam trying to post some string data to a servlet.
The servlet reads 2 parameters from url.And reads the xml string message thro post method.
So in the client program, I added those parameters to the URL directly like this,
"http://localhost/servlet/test?action1=value1&action2=value2" ,and created url object .
And using URLConnection iam trying to post the xml string.
But the servlet does not read the parameter values.Is my approach is correct?
client code:
package test;
import java.net.*;
import java.io.*;
import java.util.*;
public class Testxml{
public static void main(String ars[])
String XML="<?xml version='1.0'?><Test><msg>test message</msg></Test>";
String server="http://localhost/servlet/test";
String encodeString = URLEncoder.encode("action1") + "=" + URLEncoder.encode("something1")+"&"+URLEncoder.encode("action2") + "=" + URLEncoder.encode("something2");
try{
URL u = new URL(server+"?"+encodeString);
URLConnection uc = u.openConnection();
uc.setDoOutput(true);
uc.setUseCaches(false);
uc.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
OutputStream out = uc.getOutputStream();
PrintWriter wout = new PrintWriter(out);
wout.write(alertXML);
wout.flush();
wout.close();
System.out.println("finished");
catch(Exception e) {
System.out.println(e);
Servlet code:
package test;
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class test extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
performTask(req, res);
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
performTask(req, res);
public void performTask(HttpServletRequest request, HttpServletResponse response) {
try{
String action1=request.getParameter("action1");
String action2=request.getParameter("action2");
if(action1.equals("something1") && action1.equals("something2") )
ServletInputStream in = request.getInputStream();
byte[] buffer = new byte[1024];
String xmlMsg = "";
int len = in.read(buffer,0,buffer.length);
if(len>0)
while (len > 0 ){
xmlMsg += new String(buffer,0,len);
len = in.read(buffer);
System.out.println("xml : "+xmlMsg);
This is not working.Even,it does not invoke servlet.Is this approach is correct?.
Thanx,
Rahul.Hi,
Did you get the answer to your problem? I am facing the same problem, so if you have the solution, please share the same.
TIA
Anup -
Sending data to a Servlet. EOFException and StreamCorruptedException.
Hi!
I have a small servlet that receives some text from a client, and returns a response. The problem is that when i try to receive the data in the servlet, I get and EOFException. And when the client tries to read the response, a StreamCorruptedException is thrown. Can anybody please point me in the right direction here?
The code for servlet is as follows:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
DataInputStream in = new DataInputStream((InputStream) request.getInputStream());
String message;
String text = null;
try {
text = in.readUTF();//EOFException thrown here!
message = "100 ok";
} catch (Throwable t) {
message = "200 " + t.toString();
response.setContentType("text/html;charset=UTF-8");
response.setContentLength(message.length());
in.close();
PrintWriter out = response.getWriter();
out.println(message);
out.flush();
out.close();
System.out.println(". Received text: " + text == null ? "none" : text);
}And the code for the client:
@Test
public void test2() throws IOException, ClassNotFoundException {
String input = "This text is to be sent";
URL serverURL = new URL("http://localhost:8080/myURL");
URLConnection con = serverURL.openConnection();
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "application/x-java-serialized-object");
OutputStream outstream = con.getOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(outstream);
oos.writeObject(input);
oos.flush();
oos.close();
InputStream instr = con.getInputStream();
ObjectInputStream inputFromServlet = new ObjectInputStream(instr);//StreamCorruptedException thrown here ("invalid stream header")
String result = (String) inputFromServlet.readObject();
inputFromServlet.close();
instr.close();
System.out.println(result);
}The EOFException is thrown at the line text = in.readUTF(); in the servlet, and the StreamCorruptedException is thrown at ObjectInputStream inputFromServlet = new ObjectInputStream(instr); in the client. What is wrong here?
Edited by: Fush on Apr 15, 2008 6:59 AM
Edited by: Fush on Apr 15, 2008 7:00 AM
Edited by: Fush on Apr 15, 2008 7:03 AMYour server reads a UTF-encoded String with readUTF().
So your client should write a UTF-encoded String with writeUTF().
Your server writes lines with PrintWriter.println().
So your client should read lines with BufferedReader.readLine(). -
Hi all,
i am craeating a dimension and i did the mapping also.i get the data in that dimension table.But i am not able to get the data in the Dimesion (i.e When i right click on the dimesion which i have created,there one option is called Data Viewer,from that i am not getting data)
Can any help me about this.Hi,
Just try with the code given below... hope that helps you out....
also write a break-point statement just before the if statement and check in the debugging mode if it i_mseg table has some values or not...
if i_mseg[] is not initial.
select zzlcno zzlcdt
into i_ekpo from ekpo
for all entries in i_mseg
where ebeln = i_mseg-ebeln.
append i_ekpo.
endselect.
endif.
OR
if i_mseg[] is not initial.
select zzlcno zzlcdt
into corresponding fields of i_ekpo from ekpo
for all entries in i_mseg
where ebeln = i_mseg-ebeln.
append i_ekpo.
endselect.
endif.
Regards,
Siddarth
Maybe you are looking for
-
I have been gettting this error message in safari for 4 days. Any ideas? This is beyond frustrating. I haven't installed or downloaded anything in this time. Thanks!
-
Transaction Code assignment for Query created in SQVI
Dear All, Good morning I hope you are doing great... Can any body help me out to assign transaction code for Query which was created through SQVI transaction. Regards, Murali.
-
MacBook won't print from shared printer on Windows computer
I've been trying all day to get my MacBook to print through my wireless workgroup network. I've found detailed instructions here http://macs.about.com/od/macwindows/ss/sharewinprttig.htm. I have a Canon Pixma MX330 Printer hooked up to my Windows XP
-
Wirelessly connecting to internet
My brand new wife comes with a PC -her only fault. I have a MacBook and a Time Capsule. A new T-Mobile laptop connector (air card) works on either of our computers but loses some important files when reconnecting to mine from hers. May I plug it into
-
Hello sap guru's, I need one information ,Ant t-code for clearing other than F.13 , F.44. If any program is there for this, to clear mass clearing. there are 3000 line item which need to be cleared. Here system accicept only 999 line iteams.But i ne