yuqing ma

Greenhorn
+ Follow
since Nov 10, 2004
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 yuqing ma

OrderAction.java
package edu.sjtu.ebookstore.action;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.Arrays;
import java.text.DecimalFormat;
import edu.sjtu.ebookstore.util.SelectedBook;
import edu.sjtu.ebookstore.common.User;
import edu.sjtu.ebookstore.common.Constants;
import edu.sjtu.ebookstore.beans.Book;
import edu.sjtu.ebookstore.beans.Order;
/**
* order action
* <p>Title: ebookStore</p>
* <p>Description: ebookStore</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Shanghai Jiaotong University</p>
* @author Liu Fang
* @version 1.0
*/

public class OrderAction extends Action
{
public ActionForward execute(ActionMapping actionMapping, ActionForm actionForm, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse)
{
HttpSession session = httpServletRequest.getSession();
if(!edu.sjtu.ebookstore.service.CheckLogin.getInstance().isLogin(session))
{
return actionMapping.findForward("notLogon");
}
OrderActionForm orderActionForm = (OrderActionForm)actionForm;
User user = (User)session.getAttribute(Constants.USER_KEY);
java.util.Collection c = user.getBookList();
java.util.Iterator iterator = c.iterator();
SelectedBook[] bookList = new SelectedBook[c.size()];
for(int n=0;iterator.hasNext();n++)
{
Book book = (Book)iterator.next();
bookList[n] = new SelectedBook(book.getISBNID(),book.getName(),book.getAuthor(),book.getPrice());
}
orderActionForm.setBookList(bookList);
iterator = java.util.Arrays.asList(orderActionForm.getBookList()).iterator();
double totalPrice=0.0;
while(iterator.hasNext())
{
SelectedBook book = (SelectedBook)iterator.next();
Double price = Double.valueOf(book.getPrice());
totalPrice = totalPrice + price.doubleValue();
}
DecimalFormat format = new DecimalFormat("######0.00");
orderActionForm.setTotalPrice(format.format(totalPrice));
if(orderActionForm.getAction()!=null)
{
javax.sql.DataSource dataSource = (javax.sql.DataSource)this.servlet.getServletContext().getAttribute(edu.sjtu.ebookstore.common.Constants.DATASOURCE_KEY);
java.sql.Connection connection;
try
{
connection = dataSource.getConnection();
}
catch(Exception e)
{
return new ActionForward("/order.jsp");
}
SelectedBook[] booklist = orderActionForm.getBookList();
for(int n=0;n<booklist.length;n++)
{
Order order = new Order(user.getUserID(),booklist[n].getISBNID());
order.setConnection(connection);
try
{
order.saveOrder();
}
catch(java.sql.SQLException ex)
{
continue;
}
}
user.setBookList(null);
}
return new ActionForward("/order.jsp");
}
}

result rderAction.java:79:cannot find symbol
symbol:method setBookList((nulltype))
location:class edu.sjtu.ebookstore.common.User
user.setBookList(null)
^
User.java:
package edu.sjtu.ebookstore.common;

/**
* <p>Title: ebookStore</p>
* <p>Description: ebookStore</p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company: Shanghai Jiaotong University</p>
* @author Liu Fang
* @version 1.0
*/
import edu.sjtu.ebookstore.beans.Book;
import java.util.ArrayList;
/**
* session class for managing user state
*/
public class User
{
private String userID;
private java.util.ArrayList bookList = new ArrayList();
/**
* constructor
* @param userID userID
*/
public User(String userID)
{
this.userID = userID;
}
public String getUserID()
{
return userID;
}
public void setUserID(String userID)
{
this.userID = userID;
}
public java.util.ArrayList getBookList()
{
return bookList;
}

/**
* Buy a new book.
* @param book
*/
public void addBook(Book book)
{
java.util.Iterator iterator = this.bookList.iterator();
while(iterator.hasNext())
{
Book b = (Book)iterator.next();
if(b.getISBNID().trim().compareToIgnoreCase(book.getISBNID().trim())==0)
{
return;
}
}
this.bookList.add(book);
}
/**
* remove a book from user's cart
* @param ISBN
*/
public void removeBook(String ISBN)
{
java.util.Iterator iterator = this.bookList.iterator();
while(iterator.hasNext())
{
Book b = (Book)iterator.next();
if(b.getISBNID().trim().compareToIgnoreCase(ISBN.trim())==0)
{
this.bookList.remove(b);
}
}
}
public void setBookList(java.util.ArrayList bookList)
{
this.bookList = bookList;
}
}
I don't correct it,please help me.thank you in advance.
19 years ago
I am sorry,I pasted a wrong struts-config.xml.Really,my struts-config.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

<!-- ========== Data Source Configuration =============================== -->
<data-sources>
<data-source type="org.apache.commons.dbcp.BasicDataSource">
<set-property property="password" value="123456" />
<set-property property="minCount" value="1" />
<set-property property="maxCount" value="10" />
<set-property property="user" value="sa" />
<set-property property="driverClass" value="com.microsoft.jdbc.sqlserver.SQLServerDriver" />
<set-property property="description" value="CRM database" />
<set-property property="url" value="jdbc:microsoft:sqlserver://myq:1433;DatabaseName=crm" />
<set-property property="readOnly" value="false" />
<set-property property="autoCommit" value="true" />
<set-property property="loginTimeout" value="" />
</data-source>
</data-sources>

<!-- ========== Form Bean Definitions ================================== -->
<form-beans>
<form-bean name="ownerForm" type="com.youcompany.struts.form.OwnerForm">
<form-property name="greet" type="java.lang.String" initial="Mr." />
<form-property name="address" type="java.lang.String" />
<form-property name="email" type="java.lang.String" />
<form-property name="tel" type="java.lang.String" />
<form-property name="name" type="java.lang.String" />
</form-bean>

</form-beans>

<!-- ========== Global Exception Definitions ============================== -->
<global-exceptions />

<!-- ========== Global Forward Definitions =============================== -->
<global-forwards>
<forward name="failure" path="/failure.jsp" />

</global-forwards>

<!-- ========== Action Mapping Definitions =============================== -->
<action-mappings>
<action
attribute="ownerForm"
input="/owner.jsp"
name="ownerForm"
path="/owner"
scope="request"
type="com.youcompany.struts.action.OwnerAction"
validate="false">
<forward name="success" path="/success.jsp" />
</action>

</action-mappings>

<!-- ========== Controller Configuration ================================ -->
<controller />

<!-- ========== Message Resources Definitions ============================ -->
<message-resources parameter="com.youcompany.struts.ApplicationResources" />

<!-- ========== Plug Ins Configuration ================================= -->
</struts-config>

but I failed.

HTTP Status 503 - Servlet action is currently unavailable
type Status report
message: Servlet action is currently unavailable
description The requested service (Servlet action is currently unavailable) is not currently available.
Apache Tomcat/4.1.18
19 years ago
I try to connect a SQL Server database with struts,but I failed.please help me correct it.The example:

struts-config.xml as follows:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>

<!-- ========== Data Source Configuration =============================== -->
<data-sources />

<!-- ========== Form Bean Definitions ================================== -->
<form-beans>
<form-bean name="ownerForm" type="com.youcompany.struts.form.OwnerForm">
<form-property name="greet" type="java.lang.String" initial="Mr." />
<form-property name="address" type="java.lang.String" />
<form-property name="email" type="java.lang.String" />
<form-property name="tel" type="java.lang.String" />
<form-property name="name" type="java.lang.String" />
</form-bean>

</form-beans>

<!-- ========== Global Exception Definitions ============================== -->
<global-exceptions />

<!-- ========== Global Forward Definitions =============================== -->
<global-forwards>
<forward name="failure" path="/failure.jsp" />

</global-forwards>

<!-- ========== Action Mapping Definitions =============================== -->
<action-mappings>
<action
attribute="ownerForm"
input="/owner.jsp"
name="ownerForm"
path="/owner"
scope="request"
type="com.youcompany.struts.action.OwnerAction"
validate="false">
<forward name="success" path="/success.jsp" />
</action>

</action-mappings>

<!-- ========== Controller Configuration ================================ -->
<controller />

<!-- ========== Message Resources Definitions ============================ -->

<!-- ========== Plug Ins Configuration ================================= -->
<message-resources parameter="com.youcompany.struts.ApplicationResources" />
</struts-config>

OwnerForm.java as follows:

// Created by Xslt generator for Eclipse.
// XSL : not found (java.io.FileNotFoundException: (No such file or directory))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.youcompany.struts.form;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

/**
* OwnerForm.java created by EasyStruts - XsltGen.
* http://easystruts.sf.net
* created on 12-23-2004
*
* XDoclet definition:
* @struts:form name="ownerForm"
*/
public class OwnerForm extends ActionForm {

// --------------------------------------------------------- Instance Variables

/** greet property */
private String greet = "Mr.";

/** address property */
private String address;

/** email property */
private String email;

/** tel property */
private String tel;

/** name property */
private String name;

// --------------------------------------------------------- Methods

/**
* Method validate
* @param ActionMapping mapping
* @param HttpServletRequest request
* @return ActionErrors
*/
public ActionErrors validate(
ActionMapping mapping,
HttpServletRequest request) {

throw new UnsupportedOperationException("Generated method 'validate(...)' not implemented.");
}

/**
* Method reset
* @param ActionMapping mapping
* @param HttpServletRequest request
*/
public void reset(ActionMapping mapping, HttpServletRequest request) {
greet = "Mr.";
address = "";
email = "";
tel = "";
name = "";

}

/**
* Returns the greet.
* @return String
*/
public String getGreet() {
return greet;
}

/**
* Set the greet.
* @param greet The greet to set
*/
public void setGreet(String greet) {
this.greet = greet;
}

/**
* Returns the address.
* @return String
*/
public String getAddress() {
return address;
}

/**
* Set the address.
* @param address The address to set
*/
public void setAddress(String address) {
this.address = address;
}

/**
* Returns the email.
* @return String
*/
public String getEmail() {
return email;
}

/**
* Set the email.
* @param email The email to set
*/
public void setEmail(String email) {
this.email = email;
}

/**
* Returns the tel.
* @return String
*/
public String getTel() {
return tel;
}

/**
* Set the tel.
* @param tel The tel to set
*/
public void setTel(String tel) {
this.tel = tel;
}

/**
* Returns the name.
* @return String
*/
public String getName() {
return name;
}

/**
* Set the name.
* @param name The name to set
*/
public void setName(String name) {
this.name = name;
}

}

OwnerAction.java as follows:

// Created by Xslt generator for Eclipse.
// XSL : not found (java.io.FileNotFoundException: (No such file or directory))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.youcompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.sql.DataSource;
import java.sql.SQLException;
import com.youcompany.struts.form.OwnerForm;

/**
* OwnerAction.java created by EasyStruts - XsltGen.
* http://easystruts.sf.net
* created on 12-23-2004
*
* XDoclet definition:
* @struts:action path="/owner" name="ownerForm" input="/owner.jsp" validate="true"
* @struts:action-forward name="/success.jsp" path="/success.jsp"
*/
public class OwnerAction extends Action {

// --------------------------------------------------------- Instance Variables

// --------------------------------------------------------- Methods

/**
* Method execute
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
OwnerForm ownerForm = (OwnerForm) form;
String greet = ownerForm.getGreet();
String name = ownerForm.getName();
request.setAttribute("name", name);
request.setAttribute("greet", greet);
String address = ownerForm.getAddress();
String email = ownerForm.getEmail();
String tel = ownerForm.getTel();

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

DataSource dataSource = (DataSource)servlet.getServletContext().getAttribute(
"org.apache.struts.action.DATA_SOURCE");
try {
conn = dataSource.getConnection();
stmt = conn.createStatement();
int id = 0;
rs = stmt.executeQuery("select max(id) as counter from owner");
while(rs.next()){
id = rs.getInt("counter");
}
id += 1;
stmt.executeUpdate("insert into owner values("+id+
", '"+greet+"', '"+name+"', '"+email+"', '"+address+"', "+tel+")");
rs.close();
stmt.close();
conn.close();
}
catch(SQLException e){
throw new SQLException("database error");
}

return (mapping.findForward("success"));

}

}
// Created by Xslt generator for Eclipse.
// XSL : not found (java.io.FileNotFoundException: (No such file or directory))
// Default XSL used : easystruts.jar$org.easystruts.xslgen.JavaClass.xsl

package com.youcompany.struts.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.sql.DataSource;
import java.sql.SQLException;
import com.youcompany.struts.form.OwnerForm;

/**
* OwnerAction.java created by EasyStruts - XsltGen.
* http://easystruts.sf.net
* created on 12-23-2004
*
* XDoclet definition:
* @struts:action path="/owner" name="ownerForm" input="/owner.jsp" validate="true"
* @struts:action-forward name="/success.jsp" path="/success.jsp"
*/
public class OwnerAction extends Action {

// --------------------------------------------------------- Instance Variables

// --------------------------------------------------------- Methods

/**
* Method execute
* @param ActionMapping mapping
* @param ActionForm form
* @param HttpServletRequest request
* @param HttpServletResponse response
* @return ActionForward
* @throws Exception
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws Exception {
OwnerForm ownerForm = (OwnerForm) form;
String greet = ownerForm.getGreet();
String name = ownerForm.getName();
request.setAttribute("name", name);
request.setAttribute("greet", greet);
String address = ownerForm.getAddress();
String email = ownerForm.getEmail();
String tel = ownerForm.getTel();

Connection conn = null;
Statement stmt = null;
ResultSet rs = null;

DataSource dataSource = (DataSource)servlet.getServletContext().getAttribute(
"org.apache.struts.action.DATA_SOURCE");
try {
conn = dataSource.getConnection();
stmt = conn.createStatement();
int id = 0;
rs = stmt.executeQuery("select max(id) as counter from owner");
while(rs.next()){
id = rs.getInt("counter");
}
id += 1;
stmt.executeUpdate("insert into owner values("+id+
", '"+greet+"', '"+name+"', '"+email+"', '"+address+"', "+tel+")");
rs.close();
stmt.close();
conn.close();
}
catch(SQLException e){
throw new SQLException("database error");
}

return (mapping.findForward("success"));

}

}

HTTP Status 503 - Servlet action is currently unavailable
type Status report
message: Servlet action is currently unavailable
description The requested service (Servlet action is currently unavailable) is not currently available.
Apache Tomcat/4.1.18

I don't know where is wrong.
Please help me,everyone,thanks in advance.
19 years ago
Krishna Mohan V ,thank you very much.
19 years ago
I am using the class ActionError,but the class is deprecated since struts1.2. if anyone have struts1.1 or know web site where struts 1.1 can be downloaded,please help me. thanks,everyone!
My email is myq625@yahoo.com.cn,post it by the email.
19 years ago
what's the meaning as following?

Interfaces provide the flexibility of multiple inheritance without requiring the subclass to implement every method of its superclasses.

please give me an example,thanks for all.
19 years ago
what's the meaning as following?
Interfaces provide the flexibility of multiple inheritance without requiring the subclass to implement every method of its superclasses.
19 years ago
Here is an good example
code:

class RandString{
private static String ssource =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
private static char[] src = ssource.toCharArray();
public static class
RandCharGenerator implements CharGenerator {
public char next() {
return src[r.nextInt(src.length)];
}
}
public static class
RandStringGenerator implements Generator {
private int len;
private RandCharGenerator cg = new RandCharGenerator();
public RandStringGenerator(int length) {
len = length;
}
public Object next() {
char[] buf = new char[len];
for(int i = 0; i < len; i++)
buf[i] = cg.next();
return new String(buf);
}
}
}
19 years ago
interface A{
void printA();
}

interface B{
void pirntB();
void f();
}
class AB implements A,B
{
public void printA(){
System.out.println("Hi,I'm interface A");
}
public void printB(){
System.out.println("Hi,I'm interface B");
}
public static void main(String[] args)
{
AB ab=new AB();
ab.printA();
ab.printB();

}
}
---------- Java Compile ----------
AB.java:9: AB is not abstract and does not override abstract method f() in B
class AB implements A,B
^
1 error

Interfaces provide the flexibility of multiple inheritance without requiring the subclass to implement every method of its superclasses.
why here can't compile.
thankx in advance.
19 years ago
I see,thank you,Peter Chase.
19 years ago
code:

//: c11:Collection1.java
// Things you can do with all Collections.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
import com.bruceeckel.simpletest.*;
import java.util.*;
import com.bruceeckel.util.*;

public class Collection1 {
private static Test monitor = new Test();
public static void main(String[] args) {
Collection c = new ArrayList();
Collections2.fill(c, Collections2.countries, 5);
c.add("ten");
c.add("eleven");
System.out.println(c);
// Make an array from the List:
Object[] array = c.toArray();
// Make a String array from the List:
String[] str = (String[])c.toArray(new String[1]);
// Find max and min elements; this means
// different things depending on the way
// the Comparable interface is implemented:
System.out.println("Collections.max(c) = " +
Collections.max(c));
System.out.println("Collections.min(c) = " +
Collections.min(c));
// Add a Collection to another Collection
Collection c2 = new ArrayList();
Collections2.fill(c2, Collections2.countries, 5);
c.addAll(c2);
System.out.println(c);
c.remove(CountryCapitals.pairs[0][0]);
System.out.println(c);
c.remove(CountryCapitals.pairs[1][0]);
System.out.println(c);
// Remove all components that are
// in the argument collection:
c.removeAll(c2);
System.out.println(c);
c.addAll(c2);
System.out.println(c);
// Is an element in this Collection?
String val = CountryCapitals.pairs[3][0];
System.out.println("c.contains(" + val + ") = "
+ c.contains(val));
// Is a Collection in this Collection?
System.out.println(
"c.containsAll(c2) = " + c.containsAll(c2));
Collection c3 = ((List)c).subList(3, 5);
// Keep all the elements that are in both
// c2 and c3 (an intersection of sets):
c2.retainAll(c3);
System.out.println(c);
// Throw away all the elements
// in c2 that also appear in c3:
c2.removeAll(c3);
System.out.println("c.isEmpty() = " + c.isEmpty());
c = new ArrayList();
Collections2.fill(c, Collections2.countries, 5);
System.out.println(c);
c.clear(); // Remove all elements
System.out.println("after c.clear():");
System.out.println(c);
monitor.expect(new String[] {
"[ALGERIA, ANGOLA, BENIN, BOTSWANA, BURKINA FASO, " +
"ten, eleven]",
"Collections.max(c) = ten",
"Collections.min(c) = ALGERIA",
"[ALGERIA, ANGOLA, BENIN, BOTSWANA, BURKINA FASO, " +
"ten, eleven, BURUNDI, CAMEROON, CAPE VERDE, " +
"CENTRAL AFRICAN REPUBLIC, CHAD]",
"[ANGOLA, BENIN, BOTSWANA, BURKINA FASO, ten, " +
"eleven, BURUNDI, CAMEROON, CAPE VERDE, " +
"CENTRAL AFRICAN REPUBLIC, CHAD]",
"[BENIN, BOTSWANA, BURKINA FASO, ten, eleven, " +
"BURUNDI, CAMEROON, CAPE VERDE, " +
"CENTRAL AFRICAN REPUBLIC, CHAD]",
"[BENIN, BOTSWANA, BURKINA FASO, ten, eleven]",
"[BENIN, BOTSWANA, BURKINA FASO, ten, eleven, " +
"BURUNDI, CAMEROON, CAPE VERDE, " +
"CENTRAL AFRICAN REPUBLIC, CHAD]",
"c.contains(BOTSWANA) = true",
"c.containsAll(c2) = true",
"[BENIN, BOTSWANA, BURKINA FASO, ten, eleven, " +
"BURUNDI, CAMEROON, CAPE VERDE, " +
"CENTRAL AFRICAN REPUBLIC, CHAD]",
"c.isEmpty() = false",
"[COMOROS, CONGO, DJIBOUTI, EGYPT, " +
"EQUATORIAL GUINEA]",
"after c.clear():",
"[]"
});
}
} ///:~
---------- Java Compile ----------
Collection1.java:50: reference to List is ambiguous, both class com.bruceeckel.util.List in com.bruceeckel.util and class java.util.List in java.util match
Collection c3 = ((List)c).subList(3, 5);
^
Collection1.java:50: cannot find symbol
symbol : method subList(int,int)
location: class com.bruceeckel.util.List
Collection c3 = ((List)c).subList(3, 5);
^
Note: Some input files use unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
2 errors
Normal Termination

I don't find List.java or List.class in the package Of com\bruceeckel\util(windows system),please all help me ,thanks in advance.
19 years ago