Java Servlet :: Two Servlets Communication With Post Method

Feb 22, 2013

We have two servlets application running on same server with Java EE 6 with below mention application URL.

Servlet1 Application URL: http://<severname>/*servlet1*
Servlet2 Application URL: http://<severname>/*servlet2*

My question is how to call Servlet2 from Servlet1 with Post method without using server name. May be something like this:

servlet.invoke(servlet2).

View Replies


ADVERTISEMENT

Java Servlet :: CharConversionException During Post Method

Feb 26, 2013

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;

[Code] ....

Issue of either fixing/overcoming the actual exception and printing out the entire xml message(bad one) in ours log during the catch block.

View Replies View Related

Servlets :: How To Implement A Callback Method For A Post Async Task

Mar 26, 2015

I am developing an app with a Java Servlet backend, and I am trying to get the Async call (AsyncTask - Android Developers) to get my response message Synced with the rest of the client and being able use this information wherever I want. Without a callback method, when from the caller class I use the commands:

ServletPostAsyncTask s = new ServletPostAsyncTask();
s.execute(new Pair<Context, String>(ListViewPrenota.this, "tours"));
Tours ttours = s.tours;
Tour tour = ttours.getTours().get(0);

I receive a NullPointerException pointing to the third line Tours ttours = s.tours;, since the s.execute() method doesn't wait for the rest of the lines to get executed.To solve this I thought about implementing a callback method with interfaces in Java, but I am not sure on how to do it. For example, what class does have to implement the interface, the ServletPostAsyncTask or the caller class?

View Replies View Related

Servlets :: Java Standalone Program To JSP Communication

Aug 4, 2014

The following programs exist:

1. I have a java application which accepts bio potential data every second or two and stores it in the database. This is a socket server which accepts this data from multiple clients and spawns a new thread for processing it to store in the db.

2. I have a jsp page on tomcat server which reads historic client data from database (stored by application 1) and displays it on the page.

The socket server program in 1.) above is not running inside of tomcat server.The new requirement now is : Display all of the human data coming in live on the jsp page.Now the problem: I will now need to pass the live data from socket server (which is stand alone) to the jsp which is running on a tomcat server.

Possible solutions:

APPROACH 1: Run the socket server in the tomcat instead of stand alone and store the frequently incoming data in a java object so the jsp can access this object every second and display it on a graph.

PROBLEM : The stand alone java application does not need to be included in a tomcat server except for the fact that the jsp needs access to the live data. Also, I have read that this is not the best way.

APPROACH 2: Expose the stand alone java application as a web service and communicate with the jsp using REST architecture.

PROBLEM : The complication of using this method is that it will not have the flexibility offered by websockets or server sent events (SSE) of auto updating the latest data. The jsp will have to keep polling for new data every one second which is also not a very good option.

View Replies View Related

Current Options For Applet To Servlet Communication

Feb 12, 2014

My primary question is about which method is the best for having an applet of mine communication with a backend database of mine. In other words, I don't want to try learning a technology that is out of date or not a good fit for my goal. I purchased the O'Reilly title "Java Servlet Programming", but it seems to be very old and out of date (referencing Netscape 4, etc.) and I see a Java RMI O'Reilly title on Amazon, but it was written in 2001.

My basic goal is to allow my applet to have access to a back-end database for reading and writing. I understand that direct Applet to DB (via JDBC) access is a bad idea so my thought is to create a servlet (much like web service for lack of a better term) or an actual web service (RESTful would be my first guess) to broker the requests. I already have a very basic servlet running that has access to my database server so now I want to focus on the best method for making calls from the applet to the servlet but having said that I don't want to go down this road too far if a servlet is not the right tool for the job.

My reading has been leading me to RMI, but as I said, I don't want to focus on that if there is a better option. In a non-Java environment, I'd use a web service (REST, SOAP, etc.) and perhaps that's what I should do here as well and not even bother with a servlet per se and just go with a web service.I know there can be some subjectivity with regard to these choices and I don't need to know what the "best" one is.I don't want to use RMI if it's dead or has been surpassed by something else, for example.

Should I use a servlet? Should I use a web service? My needs are rather modest; query the database, send updates to the database, etc. Nothing too crazy.

View Replies View Related

Servlets :: HTTP Status 405 - HTTP Method POST Is Not Supported By This URL

May 5, 2014

The JSP page is opening but the problem is if l click on the ADD or EDIT button l receive the 405 error Iam using MySQL and glassfish server

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

[Code].....

View Replies View Related

Servlets :: Communication Sessions Between Two Applications?

Jul 22, 2014

I'm deployed application A and application B in TOMCAT server applications, the U1 user enters into the application A, he authenticates and generates a call to a page of the app B. As I was able to access the session of user U1 en A from B, it could have a single session.

View Replies View Related

Servlets :: Segregation Of POST And GET Request

Apr 8, 2014

We have a big application which is implemented in basic servlet. WE have Get and Post request in servlet. I want to provide them security if any malicious attack will happen on the form submit method. I want to make it secure. In detail, suppose if any user want to submit form/ any ajax request from my application and if he/she changes the method of submission from POST to GET then how I will recognize this?

I know that HTTPServletRequest object have GetMethod() but how I will detect that it is not changed by Tamper data/Fidler/Watir. One more way, I googled is by using GetQueryString() method but lot of the places I have query paramater in my POST request.

View Replies View Related

Servlets :: Process Both Get And Post Requests

Jun 9, 2014

I've written an HTTPServlet that send an HTTP request to one HttpListener and receive POST requests from an Http Sender.This is the code:

package sspa.huvr.git;
import java.io.DataOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;

[code]...

but when is called from the doPost method it seems that the html content is not sent from the processRequest method.

View Replies View Related

Servlets :: Unicode Post Request Parameters

Feb 10, 2014

I developed some servlet to get unicode parameters via post request. It worked perfectly fine since I set the encoding as below:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(false);
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
request.setCharacterEncoding("UTF-8");
String fileContent = request.getParameter("fileContent");
}

Now that I have set up my dev environment on a new machine with new eclipse, it does not work.

It displays Ï instead of π.

I've already tried adding URIEncoding="UTF-8" to server.xml which did not work since it only affect get not post. I figured out how to get the parameter with correct encoding on the new system:

String[] parameters = URLDecoder.decode(request.getQueryString(), "UTF-8").split("&");

But I cannot believe that this is the solution because then what's the point of having request.getParameter. I already know that:

String sss = new String(fileContent.getBytes(),"UTF-8");

would not work.

View Replies View Related

Passing File Path To Servlet Using Drag And Drop Method In Java Web

Jun 18, 2014

currently I am doing my java web application project ,and it has following steps 1) Upload the txt files 2) java servlet gets the txt file's url , read the data and do the calculation 3) pass the results

I almost finished the second step , and working on the first step .Since there are so many input files at a given time , i have to use drag and drop method to get the file's location.how to pass file's path to servlet.( servlet code can read the data from the given txt file path )software used - tomcat and netbeans 8.0

View Replies View Related

Java Servlet :: How To Get Data Directly From Request Object In Service Method

Dec 1, 2012

Is it possible to get data directly from request object in service method of servlet than why it is not possible to write directly into response object through service method instead of this we have to take PrintWriter or ServletOutputStream class object....

View Replies View Related

Sending A File To Web Page Using POST Method

Jun 22, 2011

I have an application and I would like it to send a file to a web page using POST method.

I've found the HttpClient from Apache, but I had no luck. All the tutorials and samples I can find on the net are for 3.x. I've tried adopting the samples with the HttpClient 4.1 docs, but I failed.

I have a target url of a page and source file path. I get the basic idea of what needs to happen, I am just finding it hard to implement it.

View Replies View Related

Java Applications Communication On Different Systems

Nov 1, 2014

I'm new to java and haven't develop any application before that... I need to develop an application through which i can send data from 1 computer to another computer. These communication in between the computers are those are under one router connection. Means they can connect even without internet access

Main concept is as follow

1. Java application on computer A [server side application]
2. Java application on Computer B [Client side application]
3. Java application on computer C [Client side application]

Now computer B and C communicate with computer A. but they don't know about presence of each other

View Replies View Related

Swing/AWT/SWT :: Communication Between JFrame And Java Class?

Apr 19, 2014

I have a jFrame and a Java Class. Now i have a path of image in my jFrame which I want to display in java class(Crop2). I created an object in jFrame

Crop2 d=new Crop2();

and then I'm trying to send the data to the class file but it is not working.

View Replies View Related

Communication Between Two Separate Java Program In Same Computer

Sep 20, 2012

I have two separate java Program that run on the same
computer : Program -1 & Program-2 .

Explain Program-1 :

Name of Program -1 is “InputFrame” that is a simple frame that contain a JTextField and a Button and a JTextArea .

Explain Program 2 : Name of Program-2 is “OutputFrame” that is a simple frame that contain a simple JTextArea that this JTextArea is a Instance object from a class with name of “DisplayFrame” .

This instance object from class of “DisplayFrame” added to frame of “OutputFrame”.Now I want run both Program 1 & 2 simultaneously in the same computer and when I enter a text in JTextField in Program-1 and after click on the Button “OK” that Text Entered in this JTextField In addition to JTextArea in Program-1 display In JTextArea in Program-2 .

I do not want use a share file between two Program-1 and -2 Or DataBase .I want if Program-1 run but Program-2 is not running and i enter a text in JTextFeild in Program-1 , after running Program-2 that Entered Text Displaye in JTextArea in Frame of Program-2 .(Offline Message) .Both Source code of Program-1 and Program-2 is Attached .

View Replies View Related

Java Servlet :: Showing Error While Compiling Servlet

Jan 23, 2013

I am a beginner want to compile servlet with following path

javac -classpath Program FilesApache Software FoundationTomcat 5.5commonlibservlet-api.jar;classes:.-d classes srccomexamplewebBeerSelect.java

Problem arises as follows:

javac: invalid flag: FilesApache
Usage: javac <options> <source files>
use -help for a list of possible options

View Replies View Related

Java Communication With Hardware - Show Output In Numbers And Letters

May 29, 2014

I want to make project about java communication with hardware (wiz110sr) via LAN (Rj45). And for example, my hardware have ip address 198.168.0.1 ; port: 1202, connected with my PC(via lan/Rj45). I want show the output (such as numbers and letters) from my hardware in console netbeans.

When I running my code, appear :

" Exception in thread "Thread-0" java.lang.RuntimeException: Uncompilable source code
at mypkg.startListenForTCP$1.run(startListenForTCP.ja va:48)
at java.lang.Thread.run(Thread.java:745)
BUILD SUCCESSFUL (total time: 1 second) "

Here's the code :

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import sun.rmi.runtime.Log;
 
[Code] .....

View Replies View Related

Java Socket - Client-server Communication Stuck With Multi-threading

Feb 6, 2015

Firstly, my code is just a demo of my multiplayer game (2 or more players can play simultaneously) to demonstrate my problem without any extra things. I have successfully implemented peer-to-peer (P2P) communication in my game. Later, I decided to add support for client-server communication (ie a central server which is also a player) in my game. It should be much easier than P2P. Now here is the problem:

Suppose, I have 1 server and some clients (may be 1 or more clients). They all should give the following output:

Starting...
A
B
C
E
F
...
...
Done!

They all give the above output without using multi-thread. But using multi-threading, it gives the above output only when there're 1 server and 1 client. I'm using 2 threads (1 for sending, 1 for receiving) for each Socket. That means, each client has only 2 threads for communication but the server has (2 * totalClients) threads.

I've attached my full test project. So, here I'm only showing my 2 thread classes.

ReceiveThread class:
class ReceiveThread extends Thread {
private ObjectInputStream receiveStream;
private BlockingQueue<Character> queue = new ArrayBlockingQueue<Character>(Common.totalClients);

[Code] ....

Since I've attached my full test project, I'm not showing the other 3 classes. They are ServerMain, ClientMain and Common. If I've 2 clients to be connected, then I get the following output:

Server: (Runs first)

Starting...
A
Client 1 (clientID is 1): (Runs after the server)

Starting...
A
B
B
Client 2 (clientID is 2): (Runs after Client 1)

Starting...
A

They are stuck at there, even no exception. Actually, the server and the clients are stuck at the line try { ch = queue.take(); } if more than 1 client are connected. It seems that all are trying to receive data. But without using the dedicated threads, they all work as expected even for more than 1 client. Why is this behaviour? How to solve it? Note that I have used the same SendThread and ReceiveThread classes by which I have succcessfully implemented P2P communication.

About my attached test project file:

It has 5 small .java files for the classes as stated above. It is currently faulty when using additional threads. You have to change clientID variable for each client (they are described inside). But it works as expected without additional threads. To test it without the additional threads:

Comment " TODO" linesUncomment the single lines just after " TODO" linesComment the additional thread construction lines (4 lines)

Currently, for a workaround, I'm not using the dedicated threads for sending and receiving data only for client-server communication in my multi-player game. But I'm still using these threads for P2P communication. I don't know why it is and how to solve it.This is the attached test project file as described above.

Attached File(s) : Test Project.zip (4.11K)

View Replies View Related

Servlets :: Reset URL To JSP File After Servlet Call

Feb 14, 2014

I am a JSP/Servlet newbie currently adding the first servlets to a web site that had been static all along. My local instance worked great but the servlets did not respond on the test instance. Apparently, my hosting service provider requires me to use an invoker servlet mapping.

<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>

Adding this to local web.xml broke the application but the servlets respond on test instance (when their calls are not preceded by another servlet call). A Servlet fails when it is called immediately after another servlet has been called.

What I saw happening on test is URL for first call is of the form:

xxx.org/<app-name>/servlet/<servlet-name>?Id=1

And URL for the second call became:

xxx.org/<app-name>/servlet/servlet/<servlet-name>?Id=1

The servlets are invoked using "href=servlet/<servlet-name>?Id="

How can I avoid the inclusion of 'servlet' in the URL and reset the URL to the JSP page it navigates to after processing of the servlet?

P.S.: I am also trying to enable the Invoker servlet on local so I can troubleshoot easier. I went through the changes to Tomcat's web.xml and context.xml. However, my local servlets did not respond even after calling them using "href=<servlet-name>?Id=". Is there a way I can check if my invoker is active?

View Replies View Related

Servlets :: HttpUrlConnection Redirection To Other Servlet Is Not Happening

Apr 1, 2015

I have the following code which will call the server through HttpUrlConnection.

1)

String response = HttpUtil.submitRequest(json.toJSONString(), "http://ipaddr:port/SessionMgr/validateSession?sessionId=_78998348uthjae3a&showLoginPage=true");

The above lines will call the following code:

2)

public static String submitRequest(String request, String **requestUrl**) {
try {
URL url = new URL(requestUrl);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);

[Code] ......

In the above code the form should go to the servlet as mentioned in the actionUrl, but it is again going to servlet which is in step(1).

1) May i know can we make this above html form in step(3) to submitted and redirect to the servlet in **actionUrl**.

As per the above code i am summarizing the requirement. If the session is null, I have to redirect the user to login page and validated against database and then the response should go to step(1), Is it possible?

View Replies View Related

Servlets :: If URL Already Points To A Resource - Can Servlet Still Be Mapped By This URL?

May 5, 2014

I have a link with URL say "/atom/filename.link" on one webpage on my server. On clicking it, a response will return in XML format.

In the XML there is information like:

<library id = "123" path =""/>
<document id = "1234" path =""/>

With this information I can generate a URL to another link, say /libray?id=123/document?id=1234

Now I would like to realize a function so that on clicking this link, it will be automatically redirected to that new link, which is generated from the XML file.

At first I try to use a servlet/filter in a web-app and then deploy it on the server, inside this servlet/filter I make a new URL connection with the same request URL and retrieve the response and the parse the XML data. But now the request URL points to the servlet now, not the actual XML file.

For example, if I set the set the servlet-mapping to /atom, If I try to connect to the URL /atom/filename.link inside the servlet, will it still be directed to this servlet? It's like a loop, and the real content can never be reached because now the servlet occupies its path.

View Replies View Related

Servlets :: HTML To Servlet And Come Back To Same Page With Field Values

Apr 11, 2014

i have one html page ,inside html radio button and 3 textboxes and one submit button ->action->SampleServlet.java-> from here again come back to html page with checked radio buttton value and text box value. I dont want to click back button in this case, html page to servlet->here i have to call back to my html page with checked radio button and text box value .

I tried response.redirect(original.html)-->i cant able to display checked radio button and textbox value also tried requestdispatcher forward/include,html page comes newly from starting but i dont want it,i want to view in html page with checked radio button and text box value.

View Replies View Related

Unable To Access A Method Which Is Public From Servlet

May 13, 2014

I am trying to assess a method which is public from servlet. but it gives weird error. image has been attached .....

View Replies View Related

JSP :: Translation Into Servlet DoGet / DoPost Method

Feb 26, 2014

I have the below piece of code in my jsp page.

<% double randomNum= Math.random(); %>
<%= randomNum%>

Now I am trying to run this jsp, it will be translated into servlet. When i checked the generated servlet I found both the above code snippet(scriplet and expression) came in to _jspService method. But in the internet and in many other book i found that scriplet and expression portions will come in the doGet/doPost method (which will be called from jspservice).

So any specific reason why in this case it went in to jspservice method (though I am getting desired output)? I am using tomcat 6.

View Replies View Related

JSF :: Get Data From Managed Bean Method After Servlet Filter

Feb 15, 2015

I have a situation to load data while JSF page loads. Also have a filter which populates user information from http request.

I was expecting the filter first to populate the user information and in the managed bean get method to verify the user information and get the data (from database). But in this case i see the managed bean get method is invoked before filter populates user information and i get null pointer exception because the user information is null.

I had to work around to get the user information from FacesContext in the managed bean get method because the user information wasn't available. Is there a way to make sure the filter is invoked first?

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved