Harpreet Hira

Ranch Hand
+ Follow
since Sep 27, 2001
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Harpreet Hira

This thread discusses similar problem
13 years ago
The forwarded request will NOT come back. The resource to which request has been forwarded will commit the response.

If you want the remaining code to be processed use include
13 years ago
I need to communicate with a third party webservice from whom I got the WSDL file. I used WSAD to generate client using this WSDL.
However, when I try to communicate with this webservice I get the following error.

<soap:Fault>
<faultcode>soap:Client</faultcode>
<faultstring>Operation Timed Out</faultstring>
</soap:Fault>


I am not sure how to increase the time out value. It seems that the current (probably default) timeout value is 90 seconds.

I tried to increase the timeout using -
SOAPHTTPConnection soapHTTPConnection = new SOAPHTTPConnection();
soapHTTPConnection.setTimeout(300000);
msg.setSOAPTransport(soapHTTPConnection);

Unfortunately, this doesn't seem to help much.

Any ideas, how I can fix this problem?
13 years ago
Try including the path of DLL in PATH environment variable OR
Else, if you are on Windows OS, put it in System32 folder.
13 years ago
You just need to read the object from input stream and type cast it to whatever object has been returned from the servlet.

You need to do something like this.
========================================================
URL url = new URL("servlet_address");
URLConnection con = url.openConnection();

con.setDoInput(true);
con.setDoOutput(true);

con.setUseCaches(false);
con.setDefaultUseCaches(false);

OutputStream out = con.getOutputStream();
ObjectOutputStream objOut = new ObjectOutputStream(out);
objOut.writeObject("what_ever_object_you_want_to_send");

InputStream in = con.getInputStream();
ObjectInputStream objIn = new ObjectInputStream(in);
Object result = objIn.readObject();
objOut.close();
objIn.close();

// result is the object returned by servlet
// typecast it to whatever object has been returned and use it

===============================================================
13 years ago

Efficiency should take a back-seat to what makes the most sense for the application.



I guess you missed highlighted part, " the only desire is to forward the request to another resource, then this can be much more efficiently accomplished with the RequestDispatcher"

Efficiency may take back seat sometimes. But I suggested the condition when this is more efficient.

If any one wants to implement PRG(or may be some other pattern) then forward might not fit his/her needs.
13 years ago
JSP

when i try to get parameters from the request, i get null values.


Are you looking for the parameters that originally came in the request OR are you looking for the attributes that your forwarding servlet might have set in request.

In case, you are looking for attribute then you need to use
request.getAttribute(String attributeName);

If you are looking for parameter there seems to be no reason why you shouldn't get it since it is same request object that has been passed to the forwarded servlet.
13 years ago
The "rule" should be: use a forward if the current request needs to be transferred to the new resource, use a redirect if not.

use a forward if the current request needs to be transferred to the new resource - Agreed
use a redirect if not. - why?

Doing an HTTP redirect requires a round-trip to the client. If this is not required, and the only desire is to forward the request to another resource, then this can be much more efficiently accomplished with the RequestDispatcher.
13 years ago
JSP
Here is the thumb rule - User RequestDispatcher.forward() if possible. This will save a client trip

Now the question is, how to find out the "if possible" part?

To send the request to another resource(JSP, servlet or HTML) with in the SAME Web Application you should use RequestDispatcher.forward().

To send the request across web applications you don't have much choice but to use "send redirect".
13 years ago
JSP
In web.xml within the servlet tag put <load-on-startup> tag with a numeric value specifying the order in which the servlet should be loaded.

Example -
<servlet id="Servlet_26">
<servlet-name>NbaStartupServlet</servlet-name>
<servlet-class>com.mine.StartupServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

If you have more than one servlets to load on startup, you can use int value 2,3,... to specify the order in which the servlets should load at startup.
13 years ago
Idempotent - A function, is idempotent if, whenever it is applied twice to any element, it gives the same result as if it were applied once.

The idempotent method can be safely repeated.

POST method is considered non-idempotent. The reason is that the POST is supposed to post data to the server, which means it may be used to save the data in persistent location OR to do some action based on that posted data.

Similarly, GET is NOT supposed to update data, but to get data, although we can(and we do) implement GET to update data, by posting data using query string. So, GET may sometimes behave non-idempotently.
13 years ago

java.lang.String getInitParameter(java.lang.String name)

Returns a String containing the value of the named initialization parameter, or null if the parameter does not exist.
Bookmark this API

If we have a timer on the client side aren't we maintaining session times in two places?

If we want to increase session timeout later don't we have to do in two places?

What are the major disadvatages in going this route.



Unfortunately there are NOT many options.
However, you can easily overcome the setting of timeout at 2 places. Instead of hardcoding the timeout value in JSP you can dynamically set the value using session.getMaxInactiveInterval(). This way the value set in web.xml will always be set in the client side.
13 years ago

<%@ page language="java" import="com.mypackage.MyBean" %>
<jsp:useBean id="myBean" class="MyBean" scope="session" />
<jsp:setProperty name="myBean" property="myProperty" value="FirstValue"/>



The above quoted piece of JSP code, tries to find the attribute "myBean" in session. If it doesn't find it creates one and stores it in session as an attribute named "myBean".

session. setAttribute("myBean", new MyBean() )

After that, it sets the property of the MyBean object stored in pageContext.
((MyBean)pageContext.findAttribute("myBean")).setMyProperty("FirstValue");

<jsp:include page="Second.jsp"/>


This JSP code includes the Second.jsp. Which means it executes its _jspService() method.

Second.jsp
<%@ page language="java" import="com.mypackage.MyBean" %>
<jsp:useBean id="myBean" class="MyBean" scope="application"/>
<jsp:setProperty name="myBean" property="myProperty" value="SecondValue"/>


This JSP code, tries to find the attribute "myBean" in servlet context (application). If it doesn't find it creates one and stores it in servlet context (application) as an attribute named "myBean".

application. setAttribute("myBean", new MyBean() )

After that, it sets the property of the MyBean object stored in pageContext.
((MyBean)pageContext.findAttribute("myBean")).setMyProperty("FirstValue");

pageContext.findAttribute("myBean") searches for the attribute "myBean" in page, request, session , and application scopes in order and returns the value associated or null.

Since page context searches for "myBean" in session scope before application scope it gets the "myBean" object stored in session and overrides the value of property myProperty to "FirstValue".

First.jsp
<jsp:getProperty name="myBean" property="myProperty"/>



This dispays the current value set in myProperty of myBean.
((MyBean)pageContext.findAttribute("myBean")).getMyProperty()

which displays "SecondValue"

Hope this helps.
I don't really understand the problem here.

The JSPs will always get the current data from the User object in the session. It doesn't cache this data. What do you mean, when you say you want to refresh User object.

Is your servlet(which updates the User object) not being called every time the user data is updated?

The problem i have is if a user's account is updated, i would like this user's bean to be refreshed.


Any object is session is latest one. What do you mean by refreshing?

How do i access each User object for each user in all sessions so that i can invalidate the ones i want?


If you want to share data across sessions, you either need to put it in ServletContext or you have to put it in some external resource like database.
13 years ago