Li Shangqiang

Greenhorn
+ Follow
since Mar 25, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Li Shangqiang

<p>I'm using cookie to store info, and it works in saving and retreiving cookie in the same page, but when i try to retrieve the cookie from another page, i can't get the cookie.
<p>
The code is like this:
<pre>
String cookieName2 = "cfai.UserID";
Cookie newCookie = new Cookie(cookieName2, String.valueOf(userID));
newCookie.setDomain("localhost:8080");
newCookie.setMaxAge(3600 * 24 * 30 * 365); // response.addCookie(newCookie);
...
in another page:
Cookie[] cookies = request.getCookies();
for (int i=0; i<cookies.length; i++) {
System.out.println(cookies[i].getName());
}
</pre>
My app server is Tomcat3.1
Who can give me answer?
23 years ago


I've encounted a strange problem, When i use store procedure to insert a record, the string value expanded to the length of parameter length.


for example, I declared the procedure like this the Database is MS SQLServer, the driver is JDBC-ODBC bridge)
<pre>
CREATE PROCEDURE [up_NewFwxxInfo]
@strBlockName varchar(100),
AS
insert into tbl1(BlockName) VALUES (@strBlockName)
</pre>

and i call the procedure like this:


CallableStatement stmt = conn.prepareCall("{ call up_NewFwxxInfo(?)};
stmt.setString("sky");
stmt.executeUpdate();
</pre>

Then execute a query and get result like this:
<pre>
select '-' + BlockName + "-" FROM Block WHERE BlockID=33
-sky -
</pre>

This show the string inserted expanded to the length of parameter @strBlockName. So I do a trick here:
<pre>
CREATE PROCEDURE [up_NewFwxxInfo]
@strBlockName varchar(100),
AS
select @strBlockName = RTrim(@strBlockName)
insert into tbl1(BlockName) VALUES (@strBlockName)
</pre>
This works, but can anyone give answer?
It's very strange now no problem at all. If I encountered this problem again, I'll do like what you said.


I have encountered a very strange problem: I've inserted n lines into a table, but i can just get n-1 lines in table.


The database is Access, and driver is JDBC-ODBC Bridge, code is like this:
<pre>
in = new BufferedReader(new InputStreamReader(new FileInputStream(file)));
String line, supplierId = "test";
StringTokenizer parser;
int count = 0;
while ( (line = in.readLine()) != null) {
System.out.println(line);
parser = new StringTokenizer(line, ",");
// MedId, MedCName, DemandAmount, DemandUnit, DemandPrice, ValidTime, Description
count = parser.countTokens();
if (count != 6) continue;
System.out.println("insert: " + line);
StringBuffer buf = new StringBuffer(sqlStr);
buf.append("('");
buf.append(supplierId); buf.append("','");
buf.append((String)parser.nextToken().trim()); buf.append("','"); //Medid
buf.append((String)parser.nextToken().trim()); buf.append("','"); //MedCName
buf.append((String)parser.nextToken().trim()); buf.append("','"); //SupplyAmount
buf.append((String)parser.nextToken().trim()); buf.append("','");//SupplyPrice
buf.append((String)parser.nextToken().trim()); buf.append("','");//SupplyUnit
buf.append(" ','");
buf.append(date); buf.append("',");
buf.append((String)parser.nextToken().trim()); //ValidTime
buf.append(")");
System.out.println(buf.toString());
System.out.println("insert: " + stmt.executeUpdate(buf.toString())); //return 1 to every line
}
</pre>
Who can give me answer?
Please give me a sample web.xml file. I've know config servlet like this:
<servlet>
<servlet-name>myservlet</servlet-name>
<servlet-class>MyServletClass</servlet-class>
<init-param>
<param-name>Para1</param-name>
<param-value>Value1</param-value>
</init-param>
</servlet>
But if i want to config a jsp file, what's the result? And How can i get the init parameter from the web.xml file? If you have a sample file, it will be very easy to understand.
23 years ago
JSP
i've known how to do this to a servlet, but now I want to config a jsp file in web.xml and read the config int jsp. Who can tell me?
23 years ago
JSP

I've forget somthing:


If it works fine, you can type the url: http://localhost/servet/MyImageServlet, and the image not html will show.


Now you can write a html like this to use the image:
<pre>

</pre>

Wish you success!
23 years ago


There are 3 approaches, in an article on JGuru( I don't know where now), one is the approach i use: Do your drawing code on an BufferedImage, then encode it with a JPEGEncoder to the servlet outputstream. The encoder is very easy to use, So you should just know smt about servlet.

The code is like this:

<pre>
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.awt.*;
import java.awt.image.*;
import com.sun.
//There may be syntax errors here, because i'm not on my own computer and can't get src code
//But everything is in it
public class MyImageServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
response.setContentType("image/jpeg");
//get the outputstream
OutputStream out = response.getOutputStream();
//do your drawing here
BufferedImage image = new BufferedImage(intWidth, intHeight);
Graphics g = image.getGraphics();
g.drawString("Dynamic Image", 5, 5);
//output the image
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder((OutputStream)out);encoder.encode(image);
out.flush();
out.close();
g.dispose();
//OK now!
}
}
</pre>




The sun jpeg package in in jdk1.2 and later, you can find the document in http://java.sun.com/j2se/1.3/docs/guide/2d/api-jpeg/overview-summary.html
23 years ago

I have use BufferedImage to produce a immediate image, and use Sun jpeg package class to output it in servlet, but when i draw a line, there are many colorful points around the line, just like a low-quality jpeg image.



I worked like this:


<pre>
BufferedImage image = new BufferedImage(intImgWidth, intImgHeight, BufferedImage.INT_RGB);
Graphics g = image.getGraphics();
...
g.drawLine();
g.drawString();
...
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder((OutputStream)out);
encoder.encode(image); //��������
</pre>

What's the problem: BufferedImage, JPEGEncoder, or my wrong use?
23 years ago
in my store procedures, sometime i return some numbers; but how can i get it? In this case getResultSet() generate a error, getUpdateCount() return -1. My database is SQL Server, and dirver is JDBC-ODBC Bridge
I have know that if the VM use green thread, then the application in Java can't benefit from Multi-CPU, but if the VM use native thread, then the application can make use of Multi-CPU. But, I'm very confused that i can't know anything from the VM that if it is using native thread mode. Can Yuri Gadow or other give me a more clear answer?
How can i know the JVM use green thread or native thread?
Can i regulate the JVM to use a specific thread-mode?
I'm sorry, I have found the source of error. The error is not ScrollPane's but mine. Sorry again!
23 years ago
I write a component which do drawing work itself ,then i put it in a scrollpane, and the scroll bars do appear when needed. But i think the scrollpane size (100* 100) is too small, so i set the scroll pane's size to 200*200, now the scrollbars never appear!
what can i do? i want do more than just curse AWT!
23 years ago
Brain Tenner,
Can you give the well code? It can help me very much!
Thanks!
23 years ago