Help coderanch get a
new server
by contributing to the fundraiser

Derek Zeng

Greenhorn
+ Follow
since Aug 25, 2006
Merit badge: grant badges
For More
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 Derek Zeng

When I build the project, it comes out the following error message:

BUILD FAILED
D:\temp\javapetstore-2.0-ea4.5\build.xml:70: The following error occurred while executing this line:
D:\temp\javapetstore-2.0-ea4.5\setup\setup.xml:58: org.apache.derby.client.am.DisconnectException: java.security.PrivilegedActionException: Error opening socket to server localhost on port 1527 with message : null

Please help me what is the problem.
17 years ago
i'm sorry John.
I just double-click the .jar file.
17 years ago
Thanks Ulf.
It installs all the sorce codes.
[ February 18, 2007: Message edited by: Derek Zeng ]
17 years ago
Please tell me how can i run the class file.
It seems no main thread there.
17 years ago
I download the Java Petstore 2.0 from the https://blueprints.dev.java.net/servlets/ProjectDocumentList?folderID=5315&expandFolder=5315&folderID=0
It is a jar file. Inside the jar file is a big .class file.
It should have the source codes.
How can i use it?
Thanks.
17 years ago
I am SCJP 5.0 and looking for Java/J2EE job in GTA area.
Please help me.
17 years ago
congratulations Anthony
17 years ago
I removed the following codes, it works.
I am confused the "*".
Thanks Manikandan!

<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
Congratulations!!! Roger
17 years ago
I am using Windows and Tomcat.
I access the resource by the following URL: http://localhost:8080/ex0502/CheckedServlet.
The CheckedServlet.java is just some simple codes to do test.
It supports doGet() & doPost() methods.
If the web.xml changes to the following codes, it works fine.

<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>
<servlet-name>CheckedServlet</servlet-name>
<servlet-class>webcert.ch05.ex0502.CheckedServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>CheckedServlet</servlet-name>
<url-pattern>/CheckedServlet</url-pattern>
</servlet-mapping>

How can I authenticate?
It works!
Thank you very much!
After compile the first file, it creats a subdirectory "webcert - ch04 -ex0404", and both two class files are in this folder. That's the problem.
In the web.xml file, I set <role-name> in <auth-constraint> to "*".
But it still comes out 403 error.
The following are the codes.
What is the problem? Please help me.

web.xml:
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<servlet>
<servlet-name>CheckedServlet</servlet-name>
<servlet-class>webcert.ch05.ex0502.CheckedServlet</servlet-class>
<security-role-ref>
<role-name>MGR</role-name>
<role-link>manager</role-link>
</security-role-ref>
</servlet>
<servlet-mapping>
<servlet-name>CheckedServlet</servlet-name>
<url-pattern>/CheckedServlet</url-pattern>
</servlet-mapping>

<security-constraint>
<web-resource-collection>
<web-resource-name>TheCheckedServlet</web-resource-name>
<url-pattern>/CheckedServlet</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>*</role-name>
</auth-constraint>
</security-constraint>

<security-role>
<role-name>manager</role-name>
</security-role>

</web-app>
It is the same problem.
I put the SessionAttrObject.class and SetSessionAttributes.java in the same directory.
Should I put the CLASS file in another directory?
Here are the codes:

SessionAttrObject.java
package webcert.ch04.ex0404;

import javax.servlet.http.*;

public class SessionAttrObject implements HttpSessionBindingListener {

private String data;

public SessionAttrObject(String val) { data = val; }

public String getData() { return data; }

public String toString() { return data; }

public void setData(String data) { this.data = data; }

public void valueBound(HttpSessionBindingEvent event) {
System.out.println(">B>B> valueBound() called for object " + getData());
}

public void valueUnbound(HttpSessionBindingEvent event) {
System.out.println(">U>U> valueUnbound() for object " + getData());
}
}


SetSessionAttributes.java
package webcert.ch04.ex0404;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SetSessionAttributes extends HttpServlet {

protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {

PrintWriter out = response.getWriter();
response.setContentType("text/html");
out.write("<HTML><HEAD>");
out.write("<TITLE>Binding Experiment</TITLE>");
out.write("</HEAD><BODY>");

String invalidate = request.getParameter("invalidate");

HttpSession session = request.getSession();
if ("true".equals(invalidate)) {
session.invalidate();
} else {
SessionAttrObject boundObject1 = new SessionAttrObject(
"Prometheus1");
SessionAttrObject boundObject2 = new SessionAttrObject(
"Prometheus2");
session.setAttribute("bound", boundObject1);
session.setAttribute("bound2", boundObject2);
session.setAttribute("nonBound", "Icarus");
session.setAttribute("bound", boundObject2);
session.setAttribute("bound", null);
}
out.write("<BR />Check console output to see what happened...");
out.write("</BODY></HTML>");
response.flushBuffer();
}
}