Servlets :: Send Data Over Network Using Httpsession?
Jan 9, 2015
I am learning few concepts in servlets. And i came across this doubt. We used to send data over network using httpsession as below.
HttpSession session = request.getSession();
Object obj = new Object();
session.setAttribute("object", obj);
And get the data in JSP with below code
<%= session.getAttribute("object")%>
However I am not sure whether HTTPSession is serializable or not.
How HTTPSession works?
View Replies
ADVERTISEMENT
Apr 9, 2015
I would like to understand how does multipart/form-data works during file upload scenario's, Does it chunks the data from client to server while transferring the files ?
View Replies
View Related
Jul 3, 2014
I have a basic HTML calculator that asks the user to input 2 integers and select from a dropdown their desired math operation:
The servlet will process the calculation and counts how many times a certain operation has been used:
The counter for Multiplication has incremented accordingly.
HTML:
<form action = "processcalc.html" method = "post">
<table>
<tr>
<td>First Operand:</td>
<td><input type = "text" name = "firstOperand" required></td>
[Code] ....
Question: However, when I press "Go Back" and process a new computation, all counters reset to 0. Is there a way without using HttpSession to persist the counter values? (It has not been taught to us, so we are not allowed to use it yet.)
For example, going back and having below input...
First Operand: 4
Operator: +
Second Operand: 5
...will result to...
Addition: 1
Subtraction: 0
Multiplication: 1 (counter from previous computation maintained)
Division: 0
View Replies
View Related
Aug 11, 2014
I'm new to json and the web. My purpose is to use json data from a server and parse it and show meaningful data to the user. I am aware of json parsing, so no sweat there. However, I would like to know how json data is sent to the front end after which it can be parsed.
Usually in my json parsing examples, I have a variable like var data = ]OR I do a getJSON on a data.json file which I have stored in the project folder. However, I want this data to come real time from a servlet. How to go about this?
So, basically my question is, how do I send real time json data from a servlet backend, say some records which I have extracted from the database using jdbc?
View Replies
View Related
Feb 15, 2015
I'm looking to figure out if it's possible to do the following:
HttpSession session = request.getSession();
session.setAttribute('name', 'Jane_Doe');
// more code here
session.setAttribute('name', 'John_Doe');
Obviously, you can use the HttpSessionAttributeListener to determine which attribute has changed. However, it doesn't return the new value but rather the old one.
You can use the HttpSessionEvent listener to determine when a session object has been changed.
Is there a way you can determine when a session object changes (and it does NOT occur when the setAttribute method is called...) and determine the updated key:value pair?
View Replies
View Related
Jan 8, 2015
I want to understand how is it possible to send data (image + text) along a single form. Here is my code:
<form method="post" action="updateAccount"
encType="multipart/form-data">
<input type="file" name="file" value="Select image ..." /> <input
type="submit" value="Start Upload" /> <br>
<textarea rows="8" cols="54" name="about">Yes
View Replies
View Related
Apr 16, 2014
I got my first project in which i need to receive some data from multiple client on network regularly(say every second) and then process that data and stored it to the database and then GUI needs to be created which display data accordingly.
While thinking for the design i thought blocking queue to implement the same. Like producer receive data from the port into a string builder and put that into the LinkedBlockingQueue. Consumer will take this data , process some work on it and store it into the database.I am using sybase ase 15 as a database.
My question is as i am receiving data very frequently which require insertion , updation and search almost every second into the database. What is the best way to improve the performance.
say i have 2 types of data is coming one having keyword 'Alarm' and other having 'ceased' so i need to use something like this
common fields in both is name and number.
if (ceased)
search into the database for particular event for which this ceased receive using name and numbe rand update the another field into it Also make separate entry for it
else
make a entry
Also as i am using 2-3 thread for consumers and thread = Number of client for the producer. So i thought to use synchronization at the consumer side which writes data into the database such that only 1 thread can write it.
View Replies
View Related
Oct 5, 2014
@RequestMapping(value = { "/mapping" }, method = RequestMethod.GET)
@ResponseBody
public Map<A, List<B>> getAsByB(HttpServletRequest httpRequest) {
return map;
}
when i try to get it by url i get an error. how can i send a response of a map as a json ?
View Replies
View Related
May 30, 2014
I have to send a request with post parameters from one web application to another web application,both are running different servers.
In my application i don't have any JSP,html only controller part which will handle request extract request parameters & based on request params i'll do a web service call.
My current requirement is based on request parameters i'll send request to another web application with received parameters.
I tried with sendRedirect() ,but it support only get() method.
how to proceed further.
View Replies
View Related
Mar 3, 2015
I am creating cash counter application. i want to generate a pdf receipt in new window and print it.
I am using jsp to take input from user and servlets to process the input.
I am able to generate a pdf but in same page. i want it to be a popup menu. How to implement it?
View Replies
View Related
Jun 25, 2014
I can now call the DB on the query I want and return results. What I know want to do is build an array of the data, forward it to the JSP page and display the bits individually.
So THis is the Servlet I havce:
package com.journaldev.jdbc.datasource;
import java.awt.List;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
[code]...
I think It is to do either with the way I am adding the values to User or its the forward:
getServletConfig().getServletContext().getRequestDispatcher("/test.jsp").forward(request, response);
View Replies
View Related
Jul 6, 2014
I write a Client/Server program,trying to send and receive a object between client and server. I use the ObjectStream but there exists an EOFException on the client side when invoking readObject() .... I've tried many times but couldn't figure it out ...
server-side code
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
try{
ObjectOutputStream out = new ObjectOutputStream(resp.getOutputStream());
ObjectInputStream in = new ObjectInputStream(req.getInputStream());
PersonalData pe = (PersonalData)in.readObject();
System.out.println(pe.getYearlySalary());
[Code] .....
View Replies
View Related
Apr 29, 2014
I am trying to connect to a local service over UDP - the simulator works fine, but my code does not... The sender is a separate thread and I have tried blocking, non-blocking, connecting, not connection, reading and re-reading the Oracle docs,
Java Code:
package my.comm;
import my.myMethods;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
[code]....
View Replies
View Related
Aug 12, 2014
I am not able to send large binary data from Java WebSocket client to Java WebSocket server. However, 1KB data transfer is working. Below is my code:
Client:
RandomAccessFile aFile = new RandomAccessFile
("c: est.txt", "r");
FileChannel inChannel = aFile.getChannel();
ByteBuffer buffer = ByteBuffer.allocate(1024);
while(inChannel.read(buffer) > 0)
{
session.getBasicRemote().sendBinary(buffer, false);
[code]...
Give me an example of WebSocket sample for large binary data transfer.
View Replies
View Related
Mar 2, 2014
I'm using netbeans to develop an application to send and receive data via RS 232 standard. I can send data but I can't read it.what can I do? I have this message in the console: Underlying input stream returned zero bytes. (I must use also threads to have application in real time but I don't understand very well....
View Replies
View Related
Jan 31, 2013
I'm creating a web applicaion. for that i want to create a registration page. and this registration details have to be stored in the database.
I'm getting the below error while trying to send the data ...
The requested resource (/cmd/InsertRegtodb) is not available.
Here cmd is project name and InsertRegtodb is servlet name.
Actually the servlet is present is the mentioned address. but it is not connecting to it
There is one more servlet in the same folder and which is accessible from another jsp. But this servlet is not accessible even though i have used same code as it is used for the servlet which worked for me previously...
View Replies
View Related
Feb 21, 2014
I am using apache-commons-fileupload to get file from client to the server.(using JSP and Servlet).
JSP/HTML
<form method="POST" action="GetFile" enctype="multipart/form-data">
<input type="file" name="datafile">
<input type="text" name="text1">
<input type="submit" value="Next">
</form>
Servlet: GetFile
System.out.println(request.getParameter("text1"));
I am able to upload the file to the server, but I am not able to get the value of text1 in the servlet (I am getting null value of text1 in the servlet), I need this textfield in the form to submit some additional information while uploading it to the server.
--> Is enctype="multipart/form-data" option of form doesn't allow other form data to be submited? if it doesn't allow it then what are the other options I have to send this additional textfield to the server.
--> Or is there any other problem in my code?
View Replies
View Related
Feb 27, 2015
I have a question in mind that this is my registration form. I am sending these values from HTML form to server and database. I have question that in my case if I click next to Add Another Mobile no in HTML.then a block is genereated and each time a new name is generated.
My Question is if I click 6 times then 6 name attribute are generated. How can I send and differentiate them on my server side.
Because at their I will use something request.getAttribute("Attr_Name");
But they are same. How to do this?.
View Replies
View Related
Jun 15, 2013
I am wondering where the attributes I put into the Httpsession are stored.
For example, if I do the following
HttpSession session = request.getSession();
session.setAttribute("usr", usr);
session.setAttribute("pwd", pwd);
where does the ("pwd", pwd) pair store?
In my case, my web application needs to use the usr and pwd to login to another application, so I have to store them somewhere. So for security reason, if the pwd is kept in the browser side, I need to encrypt it first before I put it in the session. On the other hand if it is stored in the server memory then encryption seems not necessary
View Replies
View Related
Sep 29, 2014
I've the below data in my HTML.
<body>
<div class="container">
<form name="main" action="Insert_Record" method="post">
<table class="bordered">
<tr>
[Code]....
I'm getting the below error.
java.text.ParseException: Unparseable date: "09-10-14"
if i use d-MM-yyy, the output is
Thu Aug 09 00:00:00 IST 14
but i want the date in output to be.
09-10-14
below is how my data base is like.
how can i get this.
View Replies
View Related
May 3, 2014
In my project I need to add some schedule information into a schedule table in the database..
I am accepting input from a user which direct the parameters here..
I am doing all the required stuff but yet code is not working
There must be some error in date object.
I am using mysql as backend, I have used same kind of code in jsp that is working fine but this is creating error
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.logging.Level;
import java.util.logging.Logger;
[code].....
View Replies
View Related
May 29, 2014
I have an html form with 200 input fields of type text. The first input field contains the name of a book author and the remaining 199 fields hold each a title of a book that he or she has written. I also have a servlet that processes the form data and sends it to a file. The entered data is restricted to a combination of the characters "a...z A...Z". how do i go about with creating my html page. The input fields are just too many, how to retrieve the 200 values in servlet.
<html>
<head>
<script>
var k;
function testField(Expression){
k=1;
var str1="abcdefghijklmnopqrstuvwxyz ";
var sor=Expression;
[code]....
View Replies
View Related
Apr 4, 2014
i am stucked with a little error in servlets
this is my jsp page
form.jsp
<form action="InsertData" method="post" >
username:<input type="text" name="username">
Password :<input type="password" name="password">
[Code]....
i am getting wroor page not foung 404
View Replies
View Related
Mar 26, 2015
I am trying to insert data using servlet but it is not getting into database.
I have a two JSP's form from which i enter the data and using servelt trying to insert the data into database.
JSP page code:
1.add_question_list.jsp
<script language="JavaScript">
function validate(form) {
if (form.question.value == "") {
[code]...
View Replies
View Related
Aug 2, 2014
How can we insert data through java servlet?
I can insert data to table by using JSP Scriptlet easily but I have a hard time with servlet.
public class UsertToDatabase() {
public boolean inserUser(String name, String email, String pwd) throws SQLException {
PreparedStatement pstmt = null;
boolean flag = false;
System.out.println("start");
openConn();
System.out.println("start_1");
if(conn == null) {
[code]....
I am positive that the above code function fine. The problem is whenever I call UserToDB() class inside the servlet, and I got this error: java.lang.ClassNotFoundException: org.postgresql.
Driver which mean that my conn (connection) is not connected to the database but I have ensure to do so by calling openConn() before start the transaction.
This is my servlet code:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String email = request.getParameter("email");
String password = request.getParameter("password");
List<String> errList = new ArrayList<String>();
[code]....
View Replies
View Related
Jul 22, 2014
I've sample code of jsp and servlets. Below is my code.
Index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="AnnotationServlet">
[code]....
Now I want to store those username and age(in .html) somewhere and I want those information in welcome.jsp. Now, I'm storing all those in session itself(In doGet method(servlet)).
2 Doubt) Also, when I get the session in servlet HttpSession session = request.getSession(); line No. 27. The session value is org. apache. catalina. session. StandardSessionFacade@69a8bf4f...I'm expecting that session is to be empty. Because, I dint store anything until that line.
View Replies
View Related