Problem sending a httprequest to a servlet java class
i know that entering an URL like this in the browser can call the servlet class:
http://www.xxxxxxxx.com/RequestHandler?action=showallitems
but.....
what codes do i need to send a httprequest to the servlet in java coding?
thanks again.
You mean like a normal Java code, not HTML, Request Dispatch, or something like that?
If so, then you will want to use a URLConnection (HttpURLConnection). First, create a java.net.URL to the location you want. Then open a connection (which returns a URLConnection - if your URL uses an http protocol it will actually use an HttpURLConnection and can be casted).
Use the methods in java.net.HttpURLConnection to adjust the headers, and parameters, and set up the method to use. Then get the input stream to commit the request and read the response from the server.
Make sure you read the API for URLConnection and HttpURLConnection thoroughly. There are some quirks and specific order of events that need to be followed. Also read http://www.javaworld.com/javaworld/jw-03-2001/jw-0323-traps.html for info on how to properly use a URLConnection.
Similar Messages
-
Communication between 2 servlets/java classes.
Hi,
Ive a problem. Not sure if its a simple one.
I have a web app with servlets (say Servlet1, Servlet2, etc.) in it. I use a SQL query in Servlet1 and fetch an employees information (say empinfo) from the database. This is a string value. Now, I need to pass this empinfo to Servlet2.
I might sound dumb till here but please continue till the end to know what I still have to say
1. I tried using getters and setters. Servlet2 has the empinfo value I need. This is the first time Servlet2 is accessed.
2. But, think that Servlet1 is transferring the control to an html page. And, this html page submits its parameters (say manager) to Servlet2. And, when this html passes its control to Servlet2, the empinfo value I need is gone because I used empinfo as a class member/global.
3. So, when the control enters the Servlet2 the second time everything is lost and this is when I need the empinfo value.
4. I cannot make the empinfo value in Servlet2 static because it keeps changing.
Note: I tried with all these: httpsession, reflection, etc. but nothing seems to fulfill my task.
Actually, Servlet2 lets the users to download the empinfo when a link on the html page (which sends the parameters to this servlet) is clicked.
I used httpsession to store this empinfo in Servlet1 and used to grab the value in Servlet2.
Then, I ran this app on my localhost. Then:
Step1: I opened up one browser and when I clicked the link on html, I checked the empinfo value. It was fine.
Step2: I opened up another browser and when clicked the link on html, I checked the empinfo value. It worked again.
Step3: Now, I went back to the html page in the browser1 and clicked the link and checked to see the empinfo value and now it has the value of that in browser2.
The empinfo always had the latest value. Previous values are overwritten.
If I could find a way to cache the Servlet1 object to use it in Servlet2 then I think my job is half done because even if I let Servlet2 keep a reference of the Servlet1, the html page is ruining the desired result.
If anyone can let me know how to do this with normal Java classes even that works for me.
Thanks in advance.Thanks for the reply.
Actually, when I used the session the IE browser behaved properly and its the FireFox that was weird.
I think this is because Firefox uses single cookie for many instances of itself.
Thanks again. -
Problem with servicegen and how to convert java classes to webservices
I am a beginner and am trying to convert all my java code into webservices,I have
a java class Test.java and number of other third party libraries and my own java
files that are reffered in Test.java. I want to expose the public methods in Test.java
as webservices.
the serivegen part of My build.xml is as below
<servicegen
destEar="${APPLICATIONS}/${ear_file}"
warName="${war_file}">
<service
javaClassComponents="com.verizon.Test"
targetNamespace="${namespace}"
serviceName="Test"
serviceURI="/Test"
generateTypes="True"
expandMethods="True">
</service>
<classpath>
<pathelement path="${build}"/>
<pathelement path="${java.class.path}"/>
</classpath>
</servicegen>
When i run ant it complains:
[servicegen] weblogic.xml.schema.binding.BindingException: Invalid class received:
interface org.apache.crimson.tree.ElementFactory loaded from file:/apps/opt/crimson.jar!/org/apache/crimson/tree/ElementFactory.class.
All classes that will be serialized or deserialized must be non-interface, non-abstract
classes that provide a public default constructor
I have no clue,Why is Servicegen introspecting the third party class file also?I
just need the public methods in Test.java exposed and Test.java will just use
the third party library.
also,is there a way to tell servicegen to include all these java files X,Y,Z to
the war file/ear files but expose only the public methods of X in the WSDL.
Please help
thanks
SureshHi Bruce,
Thanks very much for the insight u provided.Yes one of my public methods was returning
a element factory.
But let me ask my question this way:
Is there a way to tell servicegen to take only the specified public methods in
a class to make them as webservices?
by default servicegen is taking all the public methods..,i workaround i found
is to deploy the webservice manually by writing the web-services.xml to include
only the required public methods.
thanks
Suresh
Bruce Stephens <[email protected]> wrote:
Hi Suresh,
Does your Test.java have a public method that returns the element
factory of an XML document, like "public ElementFactory
getElementFactory ();" or such?
If so, you may want to check out the supported build-in and non-built-in
data types:
http://edocs.bea.com/wls/docs81/webserv/assemble.html#1060696
Concerning your last question, you can use the excludeEJBs, includeEJBs
(in combination with the ejbJar attribute) to specify which non-built-in
data type components should be generated. Or if you use the
javaClassComponents then simply use a comma separated list of class
names.
Hope this helps,
Bruce
suresh wrote:
I am a beginner and am trying to convert all my java code into webservices,Ihave
a java class Test.java and number of other third party libraries andmy own java
files that are reffered in Test.java. I want to expose the public methodsin Test.java
as webservices.
the serivegen part of My build.xml is as below
<servicegen
destEar="${APPLICATIONS}/${ear_file}"
warName="${war_file}">
<service
javaClassComponents="com.verizon.Test"
targetNamespace="${namespace}"
serviceName="Test"
serviceURI="/Test"
generateTypes="True"
expandMethods="True">
</service>
<classpath>
<pathelement path="${build}"/>
<pathelement path="${java.class.path}"/>
</classpath>
</servicegen>
When i run ant it complains:
[servicegen] weblogic.xml.schema.binding.BindingException: Invalidclass received:
interface org.apache.crimson.tree.ElementFactory loaded from file:/apps/opt/crimson.jar!/org/apache/crimson/tree/ElementFactory.class.
All classes that will be serialized or deserialized must be non-interface,non-abstract
classes that provide a public default constructor
I have no clue,Why is Servicegen introspecting the third party classfile also?I
just need the public methods in Test.java exposed and Test.java willjust use
the third party library.
also,is there a way to tell servicegen to include all these java filesX,Y,Z to
the war file/ear files but expose only the public methods of X in theWSDL.
Please help
thanks
Suresh -
Problem While checkin in NWDI adding TableSorter.java class in src of DC
Hi
I have added TableSorter.java class in Source folder of One Develop Component and implemented the code to sort the table.It is working fine Locally.
While I am trying to checkin in NWDI it is throwing error messages like
location: package tests
private com.sap.tc.webdynpro.tests.utils.TableSorter _tableSorter;
^
/usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/com.sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java :1851: cannot resolve symbol
symbol : class TableSorter
location: package tests
public com.sap.tc.webdynpro.tests.utils.TableSorter getTableSorter() {
^
/usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/com.sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java :1859: cannot resolve symbol
symbol : class TableSorter
location: package tests
public void setTableSorter(com.sap.tc.webdynpro.tests.utils.TableSorter value) {
^
/usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/com.sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java :1886: cannot resolve symbol
symbol : class TableSorter
location: package tests
this._tableSorter = (sap.tc.webdynpro.tests.utils.TableSorter)value;
^
/usr/sap/GJ0/JC00/j2ee/cluster/server0/temp/CBS/149/.B/21713/t/47794B28F57C19FA453190A8074C0706/gwd/packages/sap.tc.webdynpro.tests.utils.TableSorter/TableBasketView.java:262: cannot resolve symbol
symbol : class TableSorter
location: class sap.tc.webdynpro.tests.utils.TableSorter.TableBasketView.java
wdContext.currentContextElement().setTableSorter((new TableSorter(table, wdThis.wdGetActSortPrice(), null)));
Please help me.
Thanks&RegardsHi,
Where exactly did you put your TableSorter.java?
It should be in src\packages\<your package foleders>\util
Please also don't forget to add your TableSorter.java in the OpenActivity which you want to check in.
I suggest there is also another way to do this but I didn't try it:
Create new Java Project DC
Put your TableSorter.java there
Add all necessary DC for build
Create two public parts (assembly and compilation)
And use this parts in your WD DC
Regards
Pavel -
Problem sending email using javamail in servlet
I try this code and make some changes of my own http://forums.sun.com/thread.jspa?threadID=695781.
When i run the program the confirmtaion shows that the mail has been sent, but when i check in my inbox there's no the message. I'm using gmail and need to authenticate the username and password. I guess the error caused in the servlet.
Here's the code for my servlet :
import java.io.*;
import java.util.Properties;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.mail.internet.*;
import javax.mail.*;
public class ServletEx extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
System.out.println("____emailservlet.doPost");
response.setContentType("text/plain");
PrintWriter out = response.getWriter();
System.out.println("______________________________");
out.println();
String to = request.getParameter("to");
System.out.println("____________________________to" + to);
String subject = request.getParameter("subject");
String msg = request.getParameter("msg");
// construct an instance of EmailSender
System.out.println("servlet_to" + to);
send(username, to, subject, msg);
//send("[email protected]", to, subject, msg);
out.println("mail sent....");
String username = "[email protected]";
String password = "my_password";
String smtp = "smtp.gmail.com";
String port = "587";
public void send(String username, String to, String subject, String msg) {
Properties props = new Properties();
props.put("mail.smtp.user", username);
props.put("mail.smtp.host", smtp);
props.put("mail.smtp.port", port);
props.put("mail.smtp.starttls.enable","true"); // just in case, but not currently necessary, oddly enough
props.put("mail.smtp.auth", "true");
//props.put("mail.smtp.debug", "true");
props.put("mail.smtp.socketFactory.port", port);
props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
SecurityManager security = System.getSecurityManager();
try
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
//session.setDebug(true);
MimeMessage message = new MimeMessage(session);
message.setText(msg);
message.setSubject(subject);
message.setFrom(new InternetAddress(username));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
Transport.send(message);
catch (Exception mex)
mex.printStackTrace();
public class SMTPAuthenticator extends javax.mail.Authenticator {
public PasswordAuthentication getPasswordAuthentication(String username, String password)
return new PasswordAuthentication(username, password);
}Actually it's been a long time for me to develope this program, especially with the authenticate smtp. Any help would be very appreciated :)Accordingly to your stackTrace, I think that you miss some utility jar from Geronimo app. server.
As you are using Application server that is J2EE compliant, so there is an own JavaMail implementation embeded and used by the Server. To fix this problem you have to find and add to your calsspath a jar-file that contains Base64EncoderStream.class -
(Class cast Exception)Problem while loading data fro database in java class
Dear all,
Please help me...to solve this
I have a database having two columns of String and Date Types.
In my java code i was trying to load the data to a UI.
I am successfull in loading the String type value.
But while loading date field value,is showing Class cast Exception.
What i am doing is Getting the values from database to a String[] array.
So my question is how to
get the Date field as date field itself,Then convert it to a String..Then put it in to String[] array...
Any body please help...If any one want more clarification in question i will give......Hi,
I am using GWT to display my data in a Grid.
So it will accept a Single two dimensional String array....Here i have one as String and other as Date.
So i was trying to get each row in a sindle dimensional array array[] then store it in a list.
Iteration goes up to 10 rows.After i am setting it in to a list
ie list.add(array);
Now while returning this list i am doing this
"return (String[][])list.toArray(new String[0][]);"
When i tried to get the date element to String array it is showing class cast exception. When i tried with toString() method it is showing the same problem. -
How to use a java class in difference project under a same workspace!
Hi, there:
I have a problem. I want to reuse a java class which is located in another project of the same workspace. I do not know how to set the two project setting or how to import the java class. I deeply appreciate.
Sheng-Heinclude it as a library
open project settings goto libraries and simply add your class -
Import java-classes in JSP-page
Hi,
I'm starting with JSP and with trying one of the first examples in the book "beginning J2EE 1.4" from wrox, i got following problem.
i'm trying to import a java-class in the package CH03 with
<%@ page import="Ch03.FaqCategories" %>but he didn't find the package Ch03.
I try already many things and i have no idea of the cause of the problem. So it's difficult to give information that leads to the solution.
Maybe helpfull is the direcory-structure:
jsp-page: /Ch03/welcome.jsp
java-classe: /Ch03/WEB-INF/classes/Ch03/FaqCategories.class
If you need source-codes or other information, just ask.
Thanks,
DennisThank you,
Your help was one step into the good direction and that problem is solved.
The application work now with studio one, but if i try it to work it with a stand-alone tomcat server it doesn't work anymore. I go first try to solve this problem by my self or at least try to describe the problem more exactly, before i ask for new help.
but if you have any idea, that's always welcome...
with regards,
Dennis -
Hi there folks,
I'm facing a rather nasty problem: I have deployed a number of
java classes to the database via loadjava while the rest of the
team were still developing away.
To delete classes via dropjava you need the file they were
loaded from (e.g. a .jar file). Now the .jar files have changed
during the development and using dropjava with them will leave
some files in the database.
Is there a way to get rid of all classes in one scheme without
the source files?
TIA,
Joerglist all your java classes by cursor
select object_name from all_objects where owner='SHEMA' and
object_type='JAVA CLASS'
and for all object_name execute
drop java class "object_name" -
Java class inherting C++ Class
Is it possible for a Java Class to inherit a C++ Class?
Jace (http://jace.sf.net) does this too, but it's not
what he's looking for. He would have to do the
opposite - create a C++ subclass of the existing C++
class, and override the methods so that they use
Call*Method to delegate to a Java class. Btw, what are
you doing with Jnails that is different from Jace or
JNI++?
God bless,
-Toby Reyelts
From the discussion i infer that a C++ class can inherit another C++ class, and develope the Java class which talks to the child C++ class. This is what we normally do in JNI.
But my actual problem is i want to have a Java Class which inherits a C++ class. Is it possible to have a Java Class as i mentioned. Because it is possible for a C++ class to use a Java Object and get the work done.
My scenario is like this i have C++ class having virtual methods. Java Class has to inherit this C++ class, and give implementation for the virtual methods. This java class will be passed on to C++ class finally for actul usuage.
How to achieve this. please reply at the earliest.
thanks for ur interest
Krishnarajan.A -
Calling Java code inside JSP page and sending toString on object to Servlet
Hi.
I am trying to setup a way to make testing my application easier. Using a web-based method will work best. Here is what I am trying to accomplish:
- Have a web page that will prompt the user to enter data, fill in text fields, make choices, etc. When done, they press the Submit button. I don't need to keep info between sessions. Just open browser, execute, view results, close browser, repeat.
- I then want to take this data and use some Java Classes I have to create a Java object.
- I then want to send the toString() results of this Java object to a known Java servlet. The result of the servlet's actions should be displayed as a response on the screen.
This is what I currently have (Ignore the
's - I don't know why they are showing up - its not important):
Web page:
<html>
<head><title>TestGroup</title></head>
<body>
<form name=f method=post action=http://localhost:100/Servlet>
Name: <br>
Group: <input name=group type=text><br>
<br>
<input type=submit value=Submit>
<input type=reset value=Reset>
</form>
</body>
</html>The Java code in the JSP (where to put it?):
<%
Group g = new Group();
g.setGroupName(request.getParameter("group"));
String output = g.toString(); // I want this to go to the Servlet.
%>But, now I am stuck as to how to piece these together. I have some JSP experience, but not quite like this.
As I said, when the user presses the Submit button, I want to perform the Java code above, and have the results of the toString method sent to the Servlet, plus clear all other parameters (so they are not sent to the servlet).
Does anyone have any advice/comments? I am open to alternative designs too, this is just the simplest one I could think of. If another JSP page is needed, that's fine too.
Thanks.Hi.
I am trying to setup a way to make testing my application easier. Using a web-based method will work best. Here is what I am trying to accomplish:
- Have a web page that will prompt the user to enter data, fill in text fields, make choices, etc. When done, they press the Submit button. I don't need to keep info between sessions. Just open browser, execute, view results, close browser, repeat.
- I then want to take this data and use some Java Classes I have to create a Java object.
- I then want to send the toString() results of this Java object to a known Java servlet. The result of the servlet's actions should be displayed as a response on the screen.
This is what I currently have (Ignore the
's - I don't know why they are showing up - its not important):
Web page:
<html>
<head><title>TestGroup</title></head>
<body>
<form name=f method=post action=http://localhost:100/Servlet>
Name: <br>
Group: <input name=group type=text><br>
<br>
<input type=submit value=Submit>
<input type=reset value=Reset>
</form>
</body>
</html>The Java code in the JSP (where to put it?):
<%
Group g = new Group();
g.setGroupName(request.getParameter("group"));
String output = g.toString(); // I want this to go to the Servlet.
%>But, now I am stuck as to how to piece these together. I have some JSP experience, but not quite like this.
As I said, when the user presses the Submit button, I want to perform the Java code above, and have the results of the toString method sent to the Servlet, plus clear all other parameters (so they are not sent to the servlet).
Does anyone have any advice/comments? I am open to alternative designs too, this is just the simplest one I could think of. If another JSP page is needed, that's fine too.
Thanks. -
Applet/Servlet --java.io.InvalidClassException
I'm trying to get an Applet to send data to a servlet and vice versa but I come upon this error:
java.io.InvalidClassException: javax.swing.AbstractButton; Local class not compatible:
stream classdesc serialVersionUID=-937921345538462020
local class serialVersionUID=7577615732708390153I know the client version is 1.4.1 and the server is 1.3. However, It is not fair to ask every client to make sure they have 1.3, or to have to upgrade the server to 1.4.1.
Isn't there a way to make them compatible? I heard about the serialVer program that comes with JAVA but I don't know how to use it to solve my problem.
Thanks1. You should not try to send serialized Swing objects between different Java versions. Almost every of them has the following notice in their JavaDoc:
Warning: Serialized objects of this class will not be compatible with future Swing releases. The current serialization support is appropriate for short term storage or RMI between applications running the same version of Swing.
In 1.4 you may use XML-based persistence (see XMLEncoder).
2. SerialVer is a good program, but even if you mark two classes as compatible (by assigning an explicit serialVersionUID), they should indeed be compatible. Look for specs on serialization available within the JDK Documentation bundle.
3. Core JDK classes (java.util, java.lang), as far as I remember, are compatible and can be read / written by different JDKs.
4. If you would pass your own classes through serialization from 1.3 to 1.4 or back, you probably should provide some explicit serialVersionUID for them. The reason is that 1.4 in some cases may calculate a different value than 1.3, for the same class. Look around for a list of changes between that versions. -
Problem in Passing JTree object from Servlet pgm to browser
Dear all:
Can anybody help to resolve the problem - pass the JTree obejct from servlet (Tomcat) to IE 6.0. The JTree oject alway shows invalid charcter in IE. Following is my coding.
import java.io.*;
import java.awt.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.*;
import java.net.URL;
import java.sql.*;
import java.lang.*;
import java.util.*;
import javax.swing.tree.*;
//* Testing1 give it null
public class SimpleServer extends HttpServlet
DefaultMutableTreeNode top;
DefaultMutableTreeNode EX01;
DefaultMutableTreeNode EX02;
DefaultMutableTreeNode QB01;
DefaultMutableTreeNode QB02;
DefaultMutableTreeNode N2BS;
DefaultMutableTreeNode N2TS;
//StringTokenizer st2, st1;
String query;
Connection con ;
Statement statm;
ResultSet res, backupRes;
//RowSet res, backupRes;
TreeSet treeset ;
String [] tempArray;
//ServletContext sc ;
ObjectOutputStream out ;
DefaultMutableTreeNode temp_node;
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
resp.setContentType("text/html");
// resp.setContentType("application/octet-stream");
System.out.println("create main node") ;
out = new ObjectOutputStream(resp.getOutputStream());
out.writeObject(this.set_NodeMain()); //no DB access,
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException
try
System.out.println("doPost " );
doGet(req,resp);
finally
public DefaultMutableTreeNode set_NodeMain()
top = new DefaultMutableTreeNode("Tandem");
EX01 = new DefaultMutableTreeNode("EX01");
EX02 = new DefaultMutableTreeNode("EX02");
QB01 = new DefaultMutableTreeNode("QB01");
QB02 = new DefaultMutableTreeNode("QB02");
N2BS = new DefaultMutableTreeNode("N2BS");
N2TS = new DefaultMutableTreeNode("N2TS");
top.add(EX01);
top.add(EX02);
top.add(QB01);
top.add(QB02);
top.add(N2BS);
top.add(N2TS);
return top;
}JMO - I hate seeing things like this in code:
Just use whitespace to separate the methods.
You can't just send a JTree to a browser. A browser has no idea how to render a Java object.
Put that JTree inside an applet and make it part of a JSP. That'll work.
MOD -
Unable to send a byte to a Servlet
Hello,
I am trying to execute a simple example of HTTP communication found in the Carol Hammer's book "Creating Mobile Games". I can send data from the servlet to the midlet, but i cannot send a single byte from the midlet to the servlet.
I am using WTK version 2.2 for the devlopment and Tomcat 5.5.17 for running the servlet (in localhost)
Here is the (partial) code of the midlet :
public void communicationWithServlet() {
HttpConnection connection = null;
DataOutputStream dos = null;
DataInputStream dis = null;
try {
connection = (HttpConnection)Connector.open(SERVER_URL);
((HttpConnection)connection).setRequestMethod(HttpConnection.POST);
int rc = connection.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
dos = connection.openDataOutputStream();
System.out.println("before");
dos.write((byte)100);
System.out.println("after");
dos.flush();
dis = connection.openDataInputStream();
byte[] data = new byte[10];
dis.readFully(data);
message = new String(data);
System.out.println(message);
} catch(Exception e) { }
finally {
try {
if(dis != null) { dis.close();}
if(connection != null) {connection.close();}
catch(Exception e) {}
The midlet is blocked by the instruction : dos.write((byte)100);
Here is the code of the servlet :
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class SimpleServlet extends HttpServlet {
public void doPost(HttpServletRequest requete, HttpServletResponse reponse)
throws ServletException, IOException {
InputStream is = requete.getInputStream();
int data= is.read();
reponse.setContentType("text/html");
PrintWriter out = reponse.getWriter();
out.println("Hello");
out.close();
Many thanks in advance for your helpIf I delete the following lines :
int rc = connection.getResponseCode();
if (rc != HttpConnection.HTTP_OK) {
throw new IOException("HTTP response code: " + rc);
my problem is solved : the byte is sent to the servlet
But I would understand : why the call to the getResponseCode method prevents the midlet to send the byte to the servlet ?
Thanks for your help -
Send some atributes from a Servlet to a JSP program
Hi all,
I am quite new to JSP programming and am facing a problem. I have a
Servlet code which is supposed to send some attributes to a JSP, which
will display the attribute that has been passed through the Servlet.
the Servlet code to do so is,
request.setAttribute("emailtxt","emailNewTxt");
RequestDispatcher rd=request.getRequestDispatche("/emailChangeSuc.jsp");
rd.forward(request,response);
on the JSP side, I am reciving this attribute in the following way,
<body>
<%@content_type="text/html"%>
<%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>
and am displaying the value in this way
<b><%=emailTxt%>
but I am getting an error
"non-static method getAttribute(java.lang.String) cannot be referenced
from a static context
probably occurred due to an error in /emailChangeSuc.jsp line 9:
<%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>"
Please help me solve this problem.
Thanks in anticipation,
Rajiv.
"Rajiv" == Rajiv <[email protected]> writes:
Rajiv> Hi all,
Rajiv> I am quite new to JSP programming and am facing a problem. I have a
Rajiv> Servlet code which is supposed to send some attributes to a JSP, which
Rajiv> will display the attribute that has been passed through the Servlet.
Rajiv> the Servlet code to do so is,
Rajiv> {
Rajiv> request.setAttribute("emailtxt","emailNewTxt");
Rajiv> RequestDispatcher rd=request.getRequestDispatche("/emailChangeSuc.jsp");
Rajiv> rd.forward(request,response);
Rajiv> }
Rajiv> on the JSP side, I am reciving this attribute in the following way,
Rajiv> <body>
Rajiv> <%@content_type="text/html"%>
Rajiv> <%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>
Rajiv> and am displaying the value in this way
Rajiv> <b><%=emailTxt%>
Rajiv> but I am getting an error
Rajiv> "non-static method getAttribute(java.lang.String) cannot be referenced
Rajiv> from a static context
Rajiv> probably occurred due to an error in /emailChangeSuc.jsp line 9:
Rajiv> <%! String emailTxt=HttpSession.getAttribute("emailNewTxt");%>"
First of all, you put the attribute into the request, but you're trying to read
it from the session. Change it to "request.getAttribute(...".
Second, your compile error is stating that the "getAttribute()" method of
HttpSession is not a static method. If you really needed to reference the
session, it would just be "session". Changing to "request" as in the first
point, will avoid this problem.
Third, remove the "!" from the scriptlet which declares and sets the "emailTxt"
variable. That makes it declare an instance variable instead of a local
variable. That will cause numerous problems with this.
===================================================================
David M. Karr ; Java/J2EE/XML/Unix/C++
[email protected] ; SCJP; SCWCD
Maybe you are looking for
-
Disc Makers needs a TS file format to burn DVDs
I am ready to output and make some copies of my 80 min. documentary. I need to provide the company, ( Disc Makers ) the fille in TS format but do not know how to do that. Any suggestions. I'm using Final Cut Studio 2.
-
Hi Everyone, I have a Primary Cisco ACS, called CiscoACS1, version 5.4 patch 6 with an IP address of 1.1.1.1/24 and a Secondary ACS, called CiscoACS2, version 5.4 patch 6 with an IP address of 1.1.1.2/24. Connectivity between them is ok, same subnets
-
CCMS - Missing APPLICATION ERRORS
Hi Experts, When i go to the CCMS monitoring RZ21 transaction under the node integration server i'm only able to see the node System Errors and the other node Application Errors is missing. I've done the GRMG configuartion and i can also view the XI
-
How to Transfer vids to Phone without Bluetooth or...
How to Transfer vids to Phone without Bluetooth or Connector?? Don't tell me to go buy a connector and don't ask me why not. I just want to know how to do it without those two.
-
MBP Built-in iSight and External FW iSight over iChat
I was wondering if anyone has heard of a third party program that will take video feeds from both the built in iSight in the MacBook Pro and a FireWire externam iSight. Would be nice since it is easier to maneuver the external one. Plus, two sources