Calling doGet() from in the doPost() method.
What is the conditions we have to cheak to call doGet() method from doPost().
doGet() using for request.getParameter(). the exact story is u want to get some data form html (or) data bases. it is usefu
Similar Messages
-
Hello
Please could you show through the code. I think there is something wrong with the init. If I run the servlet, it don't show a thing. It only displays: Site can't not be shown.
The doGet and also the dopost is not executed. Must I call in the doPost in the init(). And when yes how?
Thanks a lot!
Sandra Frei
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Properties;
public class update42 extends HttpServlet {
Connection con = null;
public void init() {//throws ServletException {
String url = "jdbc:DBF:/sys:copal/copal_data/data/gesch/data/stamm";
try {
//Register the JDBC driver
Class.forName("zyh.sql.dbf.DBFDriver");//.newInstance();
con = DriverManager.getConnection(url, "fre","sandy66");
catch( Exception e ) {
e.printStackTrace();
}//end catch
}//end init()
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print("in do get");
//connecting to the Database
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps = null;
try
stmt = con.createStatement();
catch (SQLException e) {e.getNextException();}
// displaying records
try
rs = stmt.executeQuery("SELECT Random, Nsa, Bzng, Bzn2, Tart, Meeh, Fstat, Nzn FROM part");
catch (SQLException e) {e.getNextException();}
try
while(rs.next()) {
out.print("<form action=\"");
out.print( req.getRequestURI() );
out.print("\" method=\"post\">");
out.print("<input type=\"text\""); //hidden
out.print(" name=\"Random\" size=\"15\" value=\"");//without 15
out.print( rs.getObject(1).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Nsa\" size=\"15\" value=\"");
out.print( rs.getObject(2).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Bzng\" size=\"25\" value=\"");
out.print( rs.getObject(3).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Bzn2\" size=\"25\" value=\"");
out.print( rs.getObject(4).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Tart\" size=\"6\" value=\"");
out.print( rs.getObject(5).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Meeh\" size=\"6\" value=\"");
out.print( rs.getObject(6).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Fstat\" size=\"6\" value=\"");
out.print( rs.getObject(7).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Nzn\" size=\"15\" value=\"");
out.print( rs.getObject(8).toString() );
out.print("\">");
out.print(" <input type=\"submit\"");
out.print(" value=\" \">");
out.print(" Update<br>");
out.print("</form>");
catch (SQLException e) {e.getNextException();}
try
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
catch (SQLException e) {
e.printStackTrace();
out.print("</pre></code>");
out.print("<p\"><a href=\"");
out.print( req.getRequestURI() );
out.print("\">Back</a></p>");
out.print("</body></html>");
out.close();
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print("<html><body>");
out.print("<code><pre>");
out.print("<table border=1>");
out.print("<tr>");
out.print("<td><font color=green>Artikelnr</font></td>");
out.print("<td><font color=green>Bezeichnung</font></td>");
out.print("<td><font color=green>Zusatzbezeichnung</font></td>");
out.print("<td><font color=green>Art</font></td>");
out.print("<td><font color=green>ME</font></td>");
out.print("<td><font color=green>Stat</font></td>");
out.print("<td><font color=green>Spezifikation</font></td>");
out.print("</tr>");
// receiving parameters
String Bzn2 = req.getParameter("Bzn2").trim();
String Meeh= req.getParameter("Meeh").trim();
String Pk = req.getParameter("Random").trim();
boolean proceed = false;
Statement stmt = null;
Statement stmt1 = null;
ResultSet rs = null;
try {
String sql;
sql = "UPDATE part SET Bzn2 = " + "'" + Bzn2 + "'" + " WHERE Random LIKE " + "'" + Pk + "'";
stmt1 = con.createStatement();
out.print(sql);
out.print(Bzn2 + Meeh + Pk);
stmt1.executeUpdate(sql);
// displaying records
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM part");
while(rs.next())
out.print("<tr>");
out.print("<td>"+ rs.getObject(1).toString()+ "</td>");
out.print("<td>"+ rs.getObject(2).toString()+ "</td>");
out.print("<td>"+ rs.getObject(3).toString()+ "</td>");
out.print("<td>"+ rs.getObject(4).toString()+ "</td>");
out.print("<td>"+ rs.getObject(5).toString()+ "</td>");
out.print("<td>"+ rs.getObject(6).toString()+ "</td>");
out.print("<td>"+ rs.getObject(7).toString()+ "</td>");
out.print("</tr>");
out.print("</table>");
catch (Exception e)
out.print(e.getMessage());
e.printStackTrace();
try
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(stmt1 != null)
stmt1.close();
catch (SQLException e) {e.getNextException();}
out.print("</pre></code>");
out.print("<p\"><a href=\"");
out.print( req.getRequestURI() );
out.print("\">Back</a></p>");
out.print("</body></html>");
out.close();
public void destroy() {
try {
//Close the connection to the database
con.close();
} catch( Exception e ) {
e.printStackTrace();
}No, do NOT call doGet() or doPost() from the init() method. Your problem is something else, but you have not provided enough information to figure out what, and there are several possibilites. "Site can't not be shown"... I doubt that is the exact message you are getting.
-
AJAX calling a servlet's synchronized doPost method
Hi all. This problem has been bugging me for a week already and still no solution in sight...
Anyway, buttons in a page I'm creating uses AJAX to call a servlet's synchronized doPost method. Once a button is clicked, the servlet calls another java class which does some back end processing. Once the called java program is finished running, the page is updated telling the user that the selected backend process has finished running. It works fine if I just run one backend process at a time...however, if try to run another backend process while the previous backend process is still running, even if the backend process is finished, the page doesn't get updated with the message informing the user that the job is finished. The page only gets updated once all the jobs have finished running. What I want to happen is that whenever a job gets finished, the page gets updated.Yeah, it has
something to do with the threads. However, I had to
synchronize the doPost method because if the doPost
method isn't synchronized, running 2 or more back end
processes simultaneously would result in the previous
backend processes being terminated, only the last
back end process would be run successfully.Yea! that's what I wanted to say! most of the time there are critical sections in your code when concurrency is there, you need to recognize them and synchronize only the critical sections.
I don't think synchronizing the whole dopost method is a better way to deal with concurrency issues. It defeats the purpose of spawning a new thread for each request(it's my personal opinion, I may be wrong).
But I got one contradiction from one member of sun forum, he says spawning thread from a servlet is not a good practice according to java EE specification. But I don't think there is any way out other than this, to deal with this scenario. I am waiting for further suggestions, so keep an eye on this thread:
http://forum.java.sun.com/thread.jspa?threadID=5149048
~cheers~ -
How can I kill all Threads of the same class from within the run() method?
Ok
I have a class called Consumer that extends Thread
I have several Consumer threans running... but, when a certain condition is true (within the run() method) in ANY of the threads, I want to kill ALL the threads of that object.
is this possible?I know this is gonna be too demanding, but can someone please tell me why my Consumer's run() method never reaches the System.out.println( "ALL CONSUMING DONE") line
Create a multi-threaded prime number calculator that is based on the producer-consumer model
using semaphores. Your program should be able to check for prime numbers in a range specified
by the user and with a variable number of threads. Example:
$ java PrimeFind 3 5000 10000
should use 1 producer and 2 consumers (3 threads in total, obviously the minimum is 2) to find all
the prime numbers in the range [5000,10000].
The producer should: use a buffer to store candidate numbers that have to be checked for
primality.
Consumers should: read from the buffer, check if a number is prime and update the status of the
program accordingly (e.g. show the number on the screen, or save it to a file)
import java.util.concurrent.Semaphore;
import java.io.*;
public class Assign1 {
static int fromThisNumber;
static int toThisNumber;
static int numberOfThreads;
static int buffer[];
static Semaphore ready; /*This semaphore is used by the Producer to signal
an "OK" to the consumers*/
static Semaphore critical; /*This is a Mutex semaphore. It allows only 1 consumer
to enter his critical section.
static Semaphore counter; /*This semaphore acts as a counter.
Instead of having a global variable
incremented each time, we just release()
this semephore when we find a prime number
Because remember that release() increments permits
static Producer prod;
static Consumer cons[];
static int in=0;
static int out=0;
static PrintWriter outFile;
public static void main (String args[]){
try{
outFile=new PrintWriter(new FileWriter("primes.txt"));
}catch(Exception e){}
numberOfThreads=Integer.parseInt(args[0]);
fromThisNumber=Integer.parseInt(args[1]);
toThisNumber=Integer.parseInt(args[2]);
buffer=new int[Integer.parseInt(args[2])-Integer.parseInt(args[1])+1];
ready=new Semaphore(0,false); /*We initialise it to 0 because we wait
for the Producer to produce atleast a
item. Suppose ready was 1 and if
Consumer ran first he would be in an
empty buffer */
critical=new Semaphore (1,false);/*We initialise it to 1 because when
the first Consumer thread tries
to enter its critical section, it
should be allowed to;
Subsequent threads will have to
wait since only 1 thread can
access its critical section at a time*/
counter=new Semaphore(0,false); // duh!
cons=new Consumer[numberOfThreads-1]; /*numberOfThreads-1 because 1 thread
is taken by the Producer*/
//Creating Producer object
prod=new Producer();
//Creating the Consumer object and start the thread.
for(int i=0;i<cons.length;i++)
cons=new Consumer();
cons[i].start();
prod.start();
//Printing to screen and file
/* for(int i=0;i<buffer.length;i++)
if(buffer[i]!=0)
System.out.println(buffer[i]);
outFile.println(buffer[i]);
System.out.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits()+"\n primes.txt written");
outFile.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits());
outFile.close();*/
static class Producer extends Thread {
public void run(){try{
while(in<buffer.length) /*'in' should always be more than 'out'.Oherwise the consumer will try to access an empty index*/
{ System.out.println("producing");
buffer[in]=fromThisNumber;
in++;
fromThisNumber++;
ready.release();
catch (Exception e){e.printStackTrace();}
System.out.println("ALL PRODUCING DONE");
static class Consumer extends Thread {
int tempout=0;
public void run(){try{
System.out.println("before while"+this.getId());
while(tempout<=in)
System.out.println("before ready"+this.getId()+" "+ready.availablePermits()+" "+in);
ready.acquire();
System.out.println("before critical.acquire"+this.getId());
critical.acquire();
tempout=out;
out++;
critical.release();
if(!isPrime(buffer[tempout]))
{System.out.println(buffer[tempout]+" by "+this.getId());buffer[tempout]=0;}
else {counter.release();System.out.println("prime added: "+buffer[tempout]+" by "+this.getId());}
critical.acquire();
tempout=out;
System.out.println("tempout:"+tempout+" of "+this.getId());
critical.release();
System.out.println("ALL CONSUMING DONE"+this.getId());
catch(Exception e){e.printStackTrace();}
//Prime number-checking method
public boolean isPrime(int n){
for(int i=2;i<=(n/2);i++)
if(n%i==0)
return false;
return true;
======================
import java.util.concurrent.Semaphore;
import java.io.*;
/* 3 questions to ask Barlas
* Why error if I start the Consumer threads before Producer
* Why does the counter semaphore always give a +1 result at the end
* Is there a way I can verify that all the work is not being done by only 1 consumer thread? In other words, the workload is being shared properly
* if I put ready.acquire() outside or inside the while loop, its not making any difference, why?
* Strangely, its not making any difference if I playing with the release() and aquire() of the semaphores, WHY?!?!
public class Assign1 {
static int fromThisNumber;
static int toThisNumber;
static int numberOfThreads;
static int buffer[];
static Semaphore ready; /*This semaphore is used by the Producer to signal
an "OK" to the consumers*/
static Semaphore critical; /*This is a Mutex semaphore. It allows only 1 consumer
to enter his critical section.
static Semaphore counter; /*This semaphore acts as a counter.
Instead of having a global variable
incremented each time, we just release()
this semephore when we find a prime number
Because remember that release() increments permits
static Producer prod;
static Consumer cons[];
static int in=0;
static int out=0;
static PrintWriter outFile;
public static void main (String args[]){
try{
outFile=new PrintWriter(new FileWriter("primes.txt"));
}catch(Exception e){}
numberOfThreads=Integer.parseInt(args[0]);
fromThisNumber=Integer.parseInt(args[1]);
toThisNumber=Integer.parseInt(args[2]);
buffer=new int[Integer.parseInt(args[2])-Integer.parseInt(args[1])+1];
ready=new Semaphore(0,false); /*We initialise it to 0 because we wait
for the Producer to produce atleast a
item. Suppose ready was 1 and if
Consumer ran first he would be in an
empty buffer */
critical=new Semaphore (1,false);/*We initialise it to 1 because when
the first Consumer thread tries
to enter its critical section, it
should be allowed to;
Subsequent threads will have to
wait since only 1 thread can
access its critical section at a time*/
counter=new Semaphore(0,false); // duh!
cons=new Consumer[numberOfThreads-1]; /*numberOfThreads-1 because 1 thread
is taken by the Producer*/
//Creating Producer object
prod=new Producer();
//Creating the Consumer object and start the thread.
for(int i=0;i<cons.length;i++)
cons[i]=new Consumer();
cons[i].start();
prod.start();
//Printing to screen and file
/* for(int i=0;i<buffer.length;i++)
if(buffer[i]!=0)
System.out.println(buffer[i]);
outFile.println(buffer[i]);
System.out.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits()+"\n primes.txt written");
outFile.println("Total primes found between "+args[1]+" and "+toThisNumber+": "+counter.availablePermits());
outFile.close();*/
static class Producer extends Thread {
public void run(){try{
while(in<buffer.length) /*'in' should always be more than 'out'.Oherwise the consumer will try to access an empty index*/
{ System.out.println("producing");
buffer[in]=fromThisNumber;
in++;
fromThisNumber++;
ready.release();
catch (Exception e){e.printStackTrace();}
System.out.println("ALL PRODUCING DONE");
static class Consumer extends Thread {
int tempout=0;
public void run(){try{
System.out.println("before while"+this.getId());
while(tempout<=in)
System.out.println("before ready"+this.getId()+" "+ready.availablePermits()+" "+in);
ready.acquire();
System.out.println("before critical.acquire"+this.getId());
critical.acquire();
tempout=out;
out++;
critical.release();
if(!isPrime(buffer[tempout]))
{System.out.println(buffer[tempout]+" by "+this.getId());buffer[tempout]=0;}
else {counter.release();System.out.println("prime added: "+buffer[tempout]+" by "+this.getId());}
critical.acquire();
tempout=out;
System.out.println("tempout:"+tempout+" of "+this.getId());
critical.release();
System.out.println("ALL CONSUMING DONE"+this.getId());
catch(Exception e){e.printStackTrace();}
//Prime number-checking method
public boolean isPrime(int n){
for(int i=2;i<=(n/2);i++)
if(n%i==0)
return false;
return true;
===========================
BTW, when I tried to change extends Thread to implements Runnable I got some kinda of error.
Actually, my program is pretty complete... its just that something if messed up in my Consumer's run() method's while loop... I think
I know guys its crazy to ask ya'll to look at so much code, but.... I'd really appreciate it. This assignment is killing me, been at it since 10 hours now.... -
I have Outlook 2013 running on Windows 7 Pro 64-Bit with Lync 2013 (Office 365 Pro). We are using a 3rd party TAPI app from FortiVoice. WE would like to be able to place calls directly from
within Outlook either by selecting a telephone number within an email and/or via the PEOPLE (Contacts) area.
What guidelines should we use to enable this feature and not have Lync 2013 intercepting the process i.e. let OUTLOOK handle placing calls?
Thanks in advance for any feedback provided.Hi,
There seems no solution for this issue so far.
Here is a fix for older versions of Outlook, maybe worth a try.
http://support.microsoft.com/kb/959625/en-us
However, if it doesn’t work, please try Malte’s reply as the workaround in the following thread. See:
http://social.technet.microsoft.com/Forums/office/en-US/3946f1bb-cc3d-41b6-ab9c-092d62d024d1/outlook-2013-tapi-calling-with-lync-installed?forum=officesetupdeploy
Thanks.
Steve Fan
TechNet Community Support
We
are trying to better understand customer views on social support experience, so your participation in this
interview project would be greatly appreciated if you have time.
Thanks for helping make community forums a great place. -
Someone calling you from outside the United States
If my friend calls me from Australia and they use either a land line or a cell phone. Am I going to get charged extra at all even if my plan is older on my cell phone? I only get 500 shared minutes a month at the moment for all types of minutes except M2M. Also what type of minutes am I going to eat (i.e: my everyday plan minutes or roaming) if I am currently in my home state in the US? Also is it going to show up on the bill differently then normal than any other type of call?
Feedback and such would be much appreciated! ThanksSuemac wrote:
If my friend calls me from Australia and they use either a land line or a cell phone. Am I going to get charged extra at all even if my plan is older on my cell phone? I only get 500 shared minutes a month at the moment for all types of minutes except M2M. Also what type of minutes am I going to eat (i.e: my everyday plan minutes or roaming) if I am currently in my home state in the US? Also is it going to show up on the bill differently then normal than any other type of call?
Feedback and such would be much appreciated! Thanks
As long as you are in the US when you receive their call, you will not get charged anything extra for receiving this call. -
Calling Graphics from Form the App Crashes
I have a problem when I call Graphics from a Form.
The Graphics file builds dynamically many boxes.
The Form file has a Chart Item with this graphics file (calling it in batch mode.
I have noticed that sometimes, when I click on the chart or when the form builds the graphic the app quits or crashes. (When I run the graphic file alone from Graphics Builder there is no problem)
Has anyone seen this? Any idea? Is it a problem with the memory? Maybe a memory limitation when a form calls a graphics file???
Thank you.I have a similar problem, and don't know why, sometimes if I close the graphics runtime there's no problem
-
Calling Transaction from ALV using OO Method
Hi,
My requirement is as follows....
I have an ALV grid with columns such as month wise Total of a GL account say JAN, feb etc...
When I double click on any of these cells it should take me to the respective Transaction (say FBL3n for the GL account and the company code) . I am able to track the GL account for which the total is displayed and company code is one of my selection criteria. In the main screen of the FBL3N we have to enter the posting date and i also want the Radio button against "all items', presently default is against 'Open Items'. So how can i proceed.
Thanks and Regards,
NamitDATA gr_event_handler TYPE REF TO lcl_event_handler . .. ..
*--Creating an instance for the event handler
CREATE OBJECT gr_event_handler .
*--Registering handler methods to handle ALV Grid events
SET HANDLER gr_event_handler->handle_double_click FOR gr_alvgrid .
CLASS lcl_event_handler IMPLEMENTATION .
*Handle Double Click
METHOD handle_double_click .
PERFORM handle_double_click USING e_row e_column es_row_no .
ENDMETHOD .
CLASS lcl_event_handler DEFINITION
*Double-click control
Methods:
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column
i_fieldrows TYPE lvc_t_row.
w_fieldrows LIKE LINE OF i_fieldrows,
CALL METHOD o_alvgrid->get_selected_rows
IMPORTING
et_index_rows = i_fieldrows.
LOOP AT i_fieldrows INTO w_fieldrows.
READ TABLE i_batch INTO w_block INDEX w_fieldrows-index.
if sy-subrc = 0.
* CLASS LCL_EVENT_RECEIVER DEFINITION
CLASS LCL_EVENT_RECEIVER DEFINITION.
* Event receiver definitions for ALV actions
PUBLIC SECTION.
CLASS-METHODS:
* Row Double click for dirll down.
HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW
E_COLUMN
ES_ROW_NO.
ENDCLASS.
* Implementation
* Every event handler that is specified below should also be set after
* the object has been created. This is done in the PBO processing.
* with the following command
* SET HANDLER oEventreceiver->handle_toolbar FOR o_Alvgrid.
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
*& Method handle_double_click
* This method is called when the user double clicks on a line to drill
* down.
* The following are exported from the ALV
* LVC_S_ROW
* LVC_S_COL
* LVC_S_ROID
METHOD HANDLE_DOUBLE_CLICK.
* The double click drill down processing should be
* coded in the form below.
PERFORM F9007_HANDLE_DOUBLE_CLICK USING E_ROW
E_COLUMN
ES_ROW_NO.
ENDMETHOD.
ENDCLASS.
*& Form F9007_HANDLE_DOUBLE_CLICK
* This form is called when the user double clicks on a line to drill
* down.
* -->P_E_ROW_ID - Row ID text
* -->P_E_COLUMN_ID - Column ID
* -->P_ES_ROW_NO - Row number
FORM f9007_handle_double_click USING p_row
p_column
p_row_no.
DATA: lw_output LIKE LINE OF i_output.
* RG:16/11/2004 - Start of Changes
* Need to check that a subtotal or grand total line has not been
* double-clicked, otherwise the report will produce a short dump!
check p_row+0(1) is initial.
* RG:16/11/2004 - End of Changes
READ TABLE i_output INDEX p_row INTO lw_output.
CASE p_column.
WHEN 'KNUMA'.
IF NOT lw_output-knuma IS INITIAL.
SET PARAMETER ID 'VBO' FIELD lw_output-knuma.
CALL TRANSACTION 'VBO3' AND SKIP FIRST SCREEN.
ENDIF.
WHEN 'VBAK_VBELN'.
IF NOT lw_output-vbak_vbeln IS INITIAL.
SET PARAMETER ID 'AUN' FIELD lw_output-vbak_vbeln.
CALL TRANSACTION 'VA03' AND SKIP FIRST SCREEN.
ENDIF.
WHEN 'VBRK_VBELN'.
IF NOT lw_output-vbrk_vbeln IS INITIAL.
SET PARAMETER ID 'VF' FIELD lw_output-vbrk_vbeln.
CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
ENDIF.
ENDCASE.
ENDFORM. " F9007_HANDLE_DOUBLE_CLICK -
is it possible to retrive or download a number/contact after its been deleted from your iphone? i deleted a number about 2-3 months ago and
now i really need it back. is it possible to retrieve this number or maybe view or bring up my entire or past call log which would have this numer in it?If it's not on icloud.com any longer you can't restore it from iCloud. (Contacts are only synced to your iCloud account, and are not included in the iCloud backup.)
-
Call doGet in the Init of a servlet?
Hello
Please could you show through the code. I think there is something wrong with the init. If I run the servlet, it don't show a thing. It only displays: Site can't not be shown.
The doGet and also the dopost is not executed. Must I call in the doPost in the init(). And when yes how?
Thanks a lot!
Sandra Frei
import java.sql.*;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Properties;
public class update42 extends HttpServlet {
Connection con = null;
public void init() {//throws ServletException {
String url = "jdbc:DBF:/sys:copal/copal_data/data/gesch/data/stamm";
try {
//Register the JDBC driver
Class.forName("zyh.sql.dbf.DBFDriver");//.newInstance();
con = DriverManager.getConnection(url, "fre","sandy66");
catch( Exception e ) {
e.printStackTrace();
}//end catch
}//end init()
public void doGet(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print("in do get");
//connecting to the Database
Statement stmt = null;
ResultSet rs = null;
PreparedStatement ps = null;
try
stmt = con.createStatement();
catch (SQLException e) {e.getNextException();}
// displaying records
try
rs = stmt.executeQuery("SELECT Random, Nsa, Bzng, Bzn2, Tart, Meeh, Fstat, Nzn FROM part");
catch (SQLException e) {e.getNextException();}
try
while(rs.next()) {
out.print("<form action=\"");
out.print( req.getRequestURI() );
out.print("\" method=\"post\">");
out.print("<input type=\"text\""); //hidden
out.print(" name=\"Random\" size=\"15\" value=\"");//without 15
out.print( rs.getObject(1).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Nsa\" size=\"15\" value=\"");
out.print( rs.getObject(2).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Bzng\" size=\"25\" value=\"");
out.print( rs.getObject(3).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Bzn2\" size=\"25\" value=\"");
out.print( rs.getObject(4).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Tart\" size=\"6\" value=\"");
out.print( rs.getObject(5).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Meeh\" size=\"6\" value=\"");
out.print( rs.getObject(6).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Fstat\" size=\"6\" value=\"");
out.print( rs.getObject(7).toString() );
out.print("\">");
out.print("<input type=\"text\"");
out.print(" name=\"Nzn\" size=\"15\" value=\"");
out.print( rs.getObject(8).toString() );
out.print("\">");
out.print(" <input type=\"submit\"");
out.print(" value=\" \">");
out.print(" Update<br>");
out.print("</form>");
catch (SQLException e) {e.getNextException();}
try
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
catch (SQLException e) {
e.printStackTrace();
out.print("</pre></code>");
out.print("<p\"><a href=\"");
out.print( req.getRequestURI() );
out.print("\">Back</a></p>");
out.print("</body></html>");
out.close();
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.print("<html><body>");
out.print("<code><pre>");
out.print("<table border=1>");
out.print("<tr>");
out.print("<td><font color=green>Artikelnr</font></td>");
out.print("<td><font color=green>Bezeichnung</font></td>");
out.print("<td><font color=green>Zusatzbezeichnung</font></td>");
out.print("<td><font color=green>Art</font></td>");
out.print("<td><font color=green>ME</font></td>");
out.print("<td><font color=green>Stat</font></td>");
out.print("<td><font color=green>Spezifikation</font></td>");
out.print("</tr>");
// receiving parameters
String Bzn2 = req.getParameter("Bzn2").trim();
String Meeh= req.getParameter("Meeh").trim();
String Pk = req.getParameter("Random").trim();
boolean proceed = false;
Statement stmt = null;
Statement stmt1 = null;
ResultSet rs = null;
try {
String sql;
sql = "UPDATE part SET Bzn2 = " + "'" + Bzn2 + "'" + " WHERE Random LIKE " + "'" + Pk + "'";
stmt1 = con.createStatement();
out.print(sql);
out.print(Bzn2 + Meeh + Pk);
stmt1.executeUpdate(sql);
// displaying records
stmt = con.createStatement();
rs = stmt.executeQuery("SELECT * FROM part");
while(rs.next())
out.print("<tr>");
out.print("<td>"+ rs.getObject(1).toString()+ "</td>");
out.print("<td>"+ rs.getObject(2).toString()+ "</td>");
out.print("<td>"+ rs.getObject(3).toString()+ "</td>");
out.print("<td>"+ rs.getObject(4).toString()+ "</td>");
out.print("<td>"+ rs.getObject(5).toString()+ "</td>");
out.print("<td>"+ rs.getObject(6).toString()+ "</td>");
out.print("<td>"+ rs.getObject(7).toString()+ "</td>");
out.print("</tr>");
out.print("</table>");
catch (Exception e)
out.print(e.getMessage());
e.printStackTrace();
try
if(rs != null)
rs.close();
if(stmt != null)
stmt.close();
if(stmt1 != null)
stmt1.close();
catch (SQLException e) {e.getNextException();}
out.print("</pre></code>");
out.print("<p\"><a href=\"");
out.print( req.getRequestURI() );
out.print("\">Back</a></p>");
out.print("</body></html>");
out.close();
public void destroy() {
try {
//Close the connection to the database
con.close();
} catch( Exception e ) {
e.printStackTrace();
}It won't get shown unless you make a call to the servlet from (e.g.) a web browser referencing it. And no - don't call doPost() or doGet() from the init() method. You might be lucky, and it might work, but it's inherently unsafe. Servlet engines will not normally call these methods until the servlet is properly initialised.
And BTW, there is no guarantee that init() will be called until the first call to the servlet, unless you specify load on startup to the servlet engine.
Your best bet is simply to type the URL of your servlet into your web browser. That will call doGet(). To call doPost(), you'll have to write a little HTML page with a form with method="post" and action=the name of your servlet.
Robin -
DoGet() & doPost() methods in servlets
If we have method=�Get� in <form> tag and the servlet is having only the doPost() method then how the servlet handles the request? Is it possible or not?
If we have method=�Post� in <form> tag and the servlet is having only the doGet() method then how the servlet handles the request? Is it possible or not?Usually business logic for get and post requests is the same, so this managed with additional process method called from doGet() and doPost().
Something like
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {...}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRequest(request, response);
} -
Reliability of the exported method calls in AM
I am wondering if the exported methods in app module are reliable. That is, when the method calls to the exported methods in AM fails for any reason, it will keep retrying until the method call succeeds. Also the marshalled method invocation packet is guaranteed to be received by the callee.
sdb2 wrote:
I have 2 questions concerning method calls in switch and for statements. Consider these two chunks of code:
1)
switch (foo.getIntegerValue()){
case 1:
case 2:
}My question is, is getIntegerValue() being called for every case statement (since it has to compare with each case) or is the method called only once?
Once, and the value returned compared to each "case" in turn.
2)
for (Foo bla : xyz.compileFoos()) {
}Is compileFoos called once or on every iteration?
I assume it gets called only once but I would like to be sure. The reason I ask is of course to avoid multiple method calls.
any help is appreciatedAlso once, and the returned list/set/array is iterated over. -
% Character causing problems with the getParameterMap() method:
Hello All,
I've run run across something I've never seen or heard of before. Basically, we have a jsp form that returns form data into a Map object from the request.getParameterMap() method. We have code in place to pull out wrong entity characters that the user may have submitted, like *, &, !, etc... The problem is we have a field that takes a 3 digit code, like 999, but if the user puts in 99%, the percent character messes up the parameter map. The request parameters go out fine from the form, but in the doPost method of the servlet the map gets changed or it changes the request parameters and 99% becomes 99/fastname somehow where f is a jsp variable for the jsp form and lastname would be the name of the next key or % is doing something else that might explain why it's overwritting the first two characters here. Not sure. Has anyone ever seen this before or have any ideas as to how to fix it? Other entity characters don't seem to do this in the app.
Any help or sympathy is appreciated!
Thanks,
JamesWell I've done more investigating and I think I've narrowed it down more. We are using JSP's and something I've never seen before, changing an http request/response object after it's been sent to the server.
Here is some of the code:
var url = etc...
var httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
httpRequest.open('POST', url, false);
httpRequest.send();
//I added this code to see what happens to my 99% value.
var xmlDocument = trim(httpRequest.responseText);
message = document.getElementById('3digitfieldName').value;
alert(message);
I added some code in because I want to see when the 99% field value gets changed. When it leaves the form we can see what the value is from: Map paramMap = request.getParameterMap();
It then goes out to the code that changes the request into the new ActiveXObject. Still at this point it's showing 99%, but when it returns back to: Map paramMap = request.getParameterMap(); the value is changed to 99/fonsignees, which is the name of the next field (parameter) of consignees. /f shows up in my debug editor, but when I print out the text it's just showing a box symbol in between 99 and onsignees. f is a variable for the form btw. What I'm thinking is that somehow, MSXML doesn't like the "%" character, but I'm not sure how to fix this? -
Wot all ways are there to call servlet from jsp
hi all
i want to know wot all methods are available
so that i can call servlet from jsp
the one which i know is using RequestDispatcher
wot are others ?
thanxhi all
i want to know wot all methods are available
so that i can call servlet from jsp
the one which i know is using RequestDispatcher
wot are others ?
thanxhi here are few ways... to call servlet from jsp...
these are just generic syntax.
Form:
<form action="ServletPath">
Link:
Directives & Action tags :
<%@ page import="ServletPath" %>
<%@ taglib uri="ServletPth" %>
<jsp:include page="ServletPath">
<jsp:forward page="ServletPath">
<jsp:useBean class="ServletPath"> (Not sure about this useBean)
hope you got your answer.
regards,
immu -
Calling IP from a Session Bean
I am looking to put some security on our EJBs based on the callers IP address. I can't seem to figure out how to get the calling IP from within the session bean. Does security need to be enabled to get this information? Is there something that I am missing?
believe the functions that you mentioned are only available within the HttpRequestObject. What I am >>actually looking for is a way to get the IP from within the SessionContext of the Session EJB or simply >>thin any part of the EJB. if you REALLY want to access IP from EJB you have to pass it as parameters to your EJB functions. Request/Response objects are not available from EJBs because you don't want to tie any other architecture(Request/Response based clients) with EJB... EJBs are designed to be accessible from any type of clients(which might not be IP based).
Because of this we are forced to implement our own. Is there a way to enable GROUPS/ROLES without >>having the EJB security enable in WebSphere?YES....you can define your groups and roles using JAAS and then in your application code...you have to to write some code to do checks before calling any Entity Beans. I am not aware of any methods to tie up the JAAS to EJB either in the deployment descriptor or any other method.
Another thing that I want to emphasize is that using IP you might not be able to accomplish what you are doing..because lets say you are assigning some rights to people with a specific IP but if u r using DHCP they might not have the same IP next time..so u will end up in more trouble. :-)
all the best....
sanjay.
Maybe you are looking for
-
Web server to download class definitions?
Hello, There's still one thing that i do not understand about RMI. I find on the website below the following quote "Classes definitions are typically made network accessible through a web server". http://java.sun.com/docs/books/tutorial/rmi/overview.
-
BPM for multiple accounts sender..
We have a scenario where we get a list of accounts from a sender file. THese accounts(will act as logins) will be used to retrieve files from their respective Unix directories. I was thinking if BPM is the only option here. To read account from th
-
Prevent mail results in spotlight
Hi, in the finder when performing searchs, I don't want emails to show. In spotlight prefs I have unticked mail, but they persist. Is there a way to not show emails, it really spams the results, and if I am looking for a mail, i'll do that in the mai
-
Where can I enter a custom frame size for a video project? I often work at non-standard aspect ratios (9x16, 32x9, etc.) Does FCPX support custom video sizes?
-
Bad color shift when importing jpgs
Jpegs look great in Photoshop - lots of contrast. After import into Dir. 11, the color is washed out and faded and contrast is gone. Seems like I read about a solution long ago for a different version but can't find what is happening. What gives? TIA