2013年9月28日星期六

eclipse configure hibernate tools

I use eclipse configure hibernate tools installed the wrong end of the time .
------ Solution ------- -------------------------------------
it will only start again the
------ For reference only ---------------------------------------

previously downloaded version is 4.0 , eclipse plug-in a variety of installation methods will not work.

finally see a bit of their own eclipse version 4.2.0 found
then download the 3.3 version of the decisive so that the.
------ For reference only -------------------------------------- -


Only you a reply , points will give you.

SQL talk : count (1) and count (*)

 This post last edited by the xj90314 on 2012-11-28 09:53:46
everyone in the program when the total number of more or less will encounter statistics sql, then . We count this function is frequently used it.
ago I remember reading a post that , count (1) than the count (*) fast, the reason is simple . I am only the first column statistics. Saying in theory, should be right. But the reality is not the case .
Let me give an example , my own writing sql. to data confidentiality , I changed the name of the table , you will forgive me .
select 
--* 
count(1)
from tt where change_date>='2012-05-28' and change_date<='2012-08-28'

Data volume: 28,753
The result is : 1 row selected in 0.26 secs.

second SQL
select 
--* 
count(*)
from tt where change_date>='2012-05-28' and change_date<='2012-08-28'

Data volume: 28,753
The result is : 1 row selected in 0.25 secs.
count (*) than the count (1) fast 0.01secs.


Well, I try to increase the amount of data . Time raised the year before.
sql:
select 
--* 
count(*)
from tt where change_date>='2011-05-28' and change_date<='2012-08-28'

Data volume: 82,805
Time Results : 1 row selected in 0.31 secs.

sql:
select 
--* 
count(1)
from tt where change_date>='2011-05-28' and change_date<='2012-08-28'

Data volume: 82,805
Time : 1 row selected in 0.26 secs.

It seems when a large quantity of data count (1) performance will be a good point , well, continue to increase the amount of data
SQL:
select 
--* 
count(1)
from tt 

The result: 243,511
Time : 1 row selected in 2.20 secs.

select 
--* 
count(*)
from tt

The result: 243,511
Time : 1 row selected in 0.12 secs.

MB, the evil it. . . . I test environment : VM4xp db2
welcome everyone refers to three four .
------ Solution - -------------------------------------------
1, saying that forum posts should go to the database made ​​;
2, different databases and different versions of different results ;
3, in fact, a lot of knowledge is constantly updated , and now most of the databases are already count (*) is optimized , so unless it is antique , otherwise basically direct count (*).
------ Solution ---------------------------------------- ----
really quickly · · ·
------ Solution ------------------------ --------------------
like Mice said , count (*) have been optimized !
count (*) time, if the table has PK, then take the PK, PK to find not null no index !
count (1) If you are one of the field has an index then take the index , PK left PK, if not , it can not speed up !
------ Solution ---------------------------------------- ----
count (*)
count (1)
count ( field )
There should be three , meaning I have already made ​​it very clear , I will not say more
------ Solution --------------- -----------------------------
theoretically , count (*) statistical results of rows and multiple columns single row the number of rows , the result is the same , it must be selected in the realization of a simple way .
------ For reference only -------------------------------------- -
share your couch really fast . .
------ For reference only -------------------------------------- -


Today, just open CSDN, see the first post is for you. . .
------ For reference only -------------------------------------- -
not send execution plan what use is made ​​of time .

even where conditions are not the same as the SQL you feel that you just change the amount of data ?

write directly count (*) If you take the index , simply do not take the table .
------ For reference only -------------------------------------- -

brother, how where it is not the same ? I said that is not clear or you can not bear to look carefully I write sql
------ For reference only ---------------------------------------


I do not have the heart to ask your primary language teacher of the current situation .

select
- *
count (*)
from tt where change_date> = '2012-05-28 'and change_date <= '2012-08-28'

select
- *
count (1)
from tt where change_date> = '2012-05-28 'and change_date <= '2012-08-28'

Do you think the database less count (1) fast , right ?

where conditions and then a change of the number of multi-point , do you think count (*) Get up , eh ?

Then you feel select count (1) from tt point this thing increase the amount of data , count (*) should be faster , it's not what you say it ?

did this thing where the conditions , and in front of you have anything ?
To compare you have to compare is select count (1) from tt where change_date> = '1900-01-01 'and change_date <= '3999-01-01'


------ For reference only ---------------------------------- -----
landlord , this error estimates are within the scope of any statement execution

Also a sql, execute n times, the time between each error range .

------ For reference only ---------------------------------- -----

brother, you see Haha, I speak only for data , the speed did not say anything , says
------ For reference only --- ------------------------------------
I did not publish any of my conclusions. . .
------ For reference only -------------------------------------- -




ah , that you think that the result is normal , is that you in the evil , not the database evil , right .

That I did not watch carefully .
------ For reference only -------------------------------------- -
select (1) faster , and I was using select (1), because the project is written like this , with everyone , or else select (*) did not level
------ for reference only ---------------------------------------
for most commercial data speaking
with a primary key or index , count (*) faster
these databases , count (1) is not to use the index , while the count (*) will automatically scan the column index ( primary key or index )

database or some files may not have this small database optimization strategies
------ For reference only ---------------------- -----------------
've always heard people say to use count (*) said
------ For reference only ----- ----------------------------------

this is what you said in the antique and of the ...
------ For reference only --------------------------------- ------
learning can not be blind , who are required to do dialectical thinking .
support the landlord issues of this right to test and share test results with a good attitude and practices.
contempt hearsay convinced, and some even show off yet unassuming man.
The above represents only personal views .
ps: I usually have all count (*), because I found in my database * or one or both fields, query plans are the same ...

------ For reference only ---------------------------------- -----
upstairs well said ! count (0) count (1) count (*) which in the end what is the difference ah , all of them were under what conditions to use ah ?

Java way to post a request on the https protocol site issues

Request online to find a variety of ways https protocol , almost all the following forms:


public class HttpsUtil{

private static class TrustAnyTrustManager implements X509TrustManager {

public void checkClientTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}

public void checkServerTrusted(X509Certificate[] chain, String authType)
throws CertificateException {
}

public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
}

private static class TrustAnyHostnameVerifier implements HostnameVerifier {
public boolean verify(String hostname, SSLSession session) {
return true;
}
}


/**
* post方式请求服务器(https协议)
* @param url
*            请求地址
* @param content
*            参数
* @param charset
*            编码
* @return
* @throws NoSuchAlgorithmException
* @throws KeyManagementException
* @throws IOException
*/
public static byte[] post(String url, String content, String charset)
throws NoSuchAlgorithmException, KeyManagementException,
IOException {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() },
new java.security.SecureRandom());

URL console = new URL(url);
HttpsURLConnection conn = (HttpsURLConnection) console.openConnection();
conn.setSSLSocketFactory(sc.getSocketFactory());
conn.setHostnameVerifier(new TrustAnyHostnameVerifier());
conn.connect();
DataOutputStream out = new DataOutputStream(conn.getOutputStream());
out.write(content.getBytes(charset));
// 刷新、关闭
out.flush();
out.close();
InputStream is = conn.getInputStream();
if (is != null) {
ByteArrayOutputStream outStream = new ByteArrayOutputStream();
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
is.close();
return outStream.toByteArray();
}
return null;
}


}


However, I used this method to access it , or not being given :
[16:38:19.303] java.lang.IllegalArgumentException: protocol = https host = null

Which god , there is wood there a good way ah.


------ Solution ------------------------------------ --------
try SSLContext sc = SSLContext.getInstance ("SSL", "SunJSSE");
------ For reference only - -------------------------------------
or not , the same error
- ----- For reference only ---------------------------------------
which line newspaper 's fault ?
------ For reference only -------------------------------------- -
reported that this line conn.connect ();
------ For reference only --------------------- ------------------
this is the wrong message
------ For reference only ----- ----------------------------------
commented conn.setHostnameVerifier (new TrustAnyHostnameVerifier ()); try
------ For reference only ------------------------------------ ---
commented , still the same error what method you use to access the https ?
------ For reference only -------------------------------------- -
requested address was wrong , https ; less behind both slash. . . Plus after it. . . Own imprudent . .

A small program output questions

Just learning JAVA, the first question is to determine whether the input is a leap year , as follows:
package experimental one ;
import java.io.IOException;

public class Year {
/ ** use if ... else statement to construct multi-branch , to determine whether a particular year is a leap year . Leap year is in line with the conditions under
face either: divisible by 4 but not divisible by 100 ; evenly divisible by four , but also divisible by 400 ** /

public static void main (String [] args) throws IOException {
/ / byte [] b = new byte [1000];
/ / int y = System.in.read (b);
int y = System.in.read ();
int a = y% 4;
int c = y% 100;
int d = y% 400;
if (a == 0 && c! = 0 | | d == 0)
{
System.out.println (y + " is a leap year " ) ;
}
else
{
System.out.println (y + " not a leap year " ) ;
}
}

}
Enter "2000" after the output is " 50 years is not a leap year ." I do not know what went wrong , why is there a "50" of the

------ Solution ------------------------------------ --------
int y = System.in.read (); this is a problem, go see Inputstream read method API
------ Solution ---- ----------------------------------------
I have just less than a self- weeks. LZ write a good feeling trouble .
This is my own writing , no other meaning .
import java.util. *;
public class lianxi {
public static void main (String [] args) {
Scanner input = new Scanner (System.in);
System.out.println (" Please enter a year: " ) ;
int year = input.nextInt ();
if (year% 4 == 0 && year% 100! = 0) {
System.out.println ();
} else if (year% 400 == 0) {
System.out.println (year + " is a leap year " ) ;
}
}
}
------ Solution ----------------------------------- ---------
import java.util.Scanner;

public class Runnian{

public static void main(String[] args) throws Exception{

Scanner scanner = new Scanner(System.in);
int year = scanner.nextInt();

int a = year%4;
int b = year%400;
int c = year%100;

if(a==0 && c!=0){
System.out.println(year+"is Runnian!");
}else if(a==0 && b==0){
System.out.println(year+"is Runnian!");
}else{
System.out.println(year+"is not Runnian!");
}
}

}
Proposed landlord wrote , enter 2000 for 50 shows this problem is System.in.read () this method caused . read () method to read a character that you enter 2000 , he only read the first one that is '2 ' this character , and this character through the ASC code will turn into an int by ASC code table query '2' the ASC code is 50 characters , so the show is 50 , it is recommended that way with my landlord to get the terminal parameters.
------ For reference only -------------------------------------- -
public abstract int read () throws IOException

from the input stream to read the next data byte. Return within the range 0-255 int byte value. If the end of the stream has been reached because no byte is available , the return value is -1 . In the input data is available, the end of the stream is detected , or an exception is thrown , this method has been blocked.

Returns:
next data byte, if the end of the stream is reached , -1 is returned.

------ For reference only ---------------------------------- -----
Thank you parents learned a reply ~ ~ ~
has been run successfully

Seek expert dwr upload files to resolve the following error Thank you ( Urgent )



Please select word document



upload file :

< ; input type = "reset" value = " reset " />








<% @ page import = "java.io.File"%>
<% @ page language = "java" import = "java.util. *, com.jspsmart.upload. *" pageEncoding = "utf-8"%>




<%
try {
mySmartUpload.initialize (pageContext);
mySmartUpload.service (request, response);
mySmartUpload.upload ();
/ / get the first upload the file name
String fn = mySmartUpload.getFiles (). getFile (0). getFileName ();

/ / String word_file = new File (getServletContext (). getRealPath ("/"). toString () + "UploadWord /" + fn); automatically get url not complete
/ / session.setAttribute ("WordFile", word_file) ;/ / added to the session
/ / session.setAttribute ("WordFile", "E :/ / Program Files / SoftwareDocument / Apache Software Foundation / Tomcat 6.0/webapps/AnalyticWord/UploadWord /" + fn) ;

/ / the uploaded file to the specified folder
mySmartUpload.save ("UploadWord /");
out.print (" has been successfully uploaded files , please see here , see whether the file uploaded successfully
");
out.print (" page mode to view Word documents ");
} catch (Exception e) {
session.setAttribute ("WordFile", "");
out.print (" Upload Word documents fail , Please try again ");
}
%>


Using the session to complete the registration



Users :

Password :





High-end atmosphere on the grade BUG -> Action in Service sporadic null pointer error

java.lang.NullPointerException
    at com.sunwave.action.privilege.UserAction.findUserPageInfo(UserAction.java:78)

omit the N word
Frame : SSH, service injection in the Action , the configuration file is as follows:
<!--用户管理-->
<bean id="userAction" class="com.sunwave.action.privilege.UserAction" scope="prototype">
<property name="userService" ref="userService"/>
<property name="systemParameterService" ref="systemParameterService"></property>
</bean>
<bean id="userService" class="com.sunwave.service.impl.privilege.UserServiceImpl"
parent="baseService">
<property name="roleService" ref="roleService"/>
<property name="empService" ref="empService"/>
<property name="systemParameterService" ref="systemParameterService"/>
<property name="userDao"><ref bean="userDao"/></property>
</bean>    
<bean id="userDao" class="com.sunwave.dao.impl.privilege.UserDaoHibImpl" 
  parent="baseDAO">
</bean>

Under normal circumstances, the error does not occur , the system posted to the public network even now , initially suspected to be high-traffic concurrency errors, doubts whether the single-case model and service related to solving ~ ~
------ Solution ------------------------------------------- -
code, and information should be posted all right,
example at com.sunwave.action.privilege.UserAction.findUserPageInfo (UserAction.java: 78) This is a code
------ Solution --------- -----------------------------------
first , perhaps , when you're testing a parameter not used to , used it on the line before this problem occurred
The second , and perhaps really high concurrent access problems , that no way to solve it on their own .
------ Solution ---------------------------------------- ----
scope = "prototype" you configure this, to break the single-case model . Which each request to create a new action a .
------ Solution ---------------------------------------- ----
method parameter problem ?
------ Solution ----------------------------- ---------------
may be timing problem
------ Solution ----------------- ---------------------------
UserAction.java: 78 is infoMap = userService.findUserByCon (start, limit, user ) ; this line ?
------ Solution ------------------------------- -------------
in this method will be added before logging parameters to a log file to facilitate later
------ Solution ------- -------------------------------------
whether through stress tests to reproduce the problem ? ;
------ Solution --------------------------------------- -----
Map session = ActionContext.getContext (). getSession ();
......
infoMap = userService.findUserByCon (start, limit, user);

you this action I have seen at least two potential safety hazard .

1. Struts has not recommended action in passing ActionContext.getContext () Gets the session . Officials have said that the phenomenon may appear empty , can go to the official website to see Kang .
2. use userService should determine whether the former is empty, it is good programming practice .
------ Solution ---------------------------------------- ----
missing jar package you carefully look at the lack of spring and struts may be associated with the package
------ For reference only -------- -------------------------------

followed conventional null pointer error message should not the code error, because the time is running locally is normal , there are other commonly used modules have similar problems
------ For reference only ----------------- ----------------------

parameters of the problem should be unlikely, even if there is , it should be ACTION mismatch , the current situation is action into the future service is null, and is even now . . .
------ For reference only -------------------------------------- -

Yes , action is polymorphic , but the service and dao default is a single case of
------ For reference only ----------- ----------------------------

not . . .
------ For reference only -------------------------------------- -

public String findUserPageInfo(){		
Map session = ActionContext.getContext().getSession();

user.setUserLevel((Integer)session.get(USER_LEVEL));
user.setLcId((Integer)session.get(USER_ID));
Integer userType = (Integer)session.get(USER_TYPE);
user.setCpUserType(userType);
if((user.getUserLevel().equals(Common.SUPER_USER_LEVEL) || user.getUserLevel().equals(Common.SYSTEM_ADMIN_LEVEL))
&& userType.equals(Common.COMPANY_USER_TYPE)){
}else{
user.setUserType(userType);
}
user.setCpTopId((Integer)session.get(Common.USER_TOPID));
if(user.getCorpId()== null)
user.setCorpId((Integer)session.get(Common.USER_COMPANYID));
infoMap=userService.findUserByCon(start,limit,user);
return SUCCESS;
}

------ For reference only ----------------------------------- ----

seeking Comments ?

------ For reference only ---------------------------------- -----


Yes

------ For reference only ---------------------------------- -----

let me testers to try, I add a catch to the exception breakpoint
------ For reference only ---------- -----------------------------

1. ah , thanks for suggestions , which are generally taken from the request session , non- I code, to make improvements
2. from a security perspective , userService is the first judgment null, but normal logic , spring injected service is not empty , we can not because some parts of the BUG and add some empty judgment redundant code bar
------ For reference only --------------------------------------- < br>
lack the nerve to stand how this kind of thing happen package . . . struts2-spring-plugin-2.0.11.1.jar I use this
------ For reference only ---------------------- -----------------
after repeated testing, I found the following situation will arise as BUG, is user login system , the establishment of session, and then use that error action directly in the web browser address input access , because without an argument , so there will be a null pointer error . As to the circumstances under which the action occurs is not clear , I think the user should not be boring to manually enter an ACTION address. . .

If this is the cause , the problem becomes how to shield focus of these operations , such as a user logs in, he wanted to try to obtain greater rights to the data , and then he would enter the user management module action addresses or is deliberately attack the server , continue to produce abnormal or even write a script, stop hair ajax request , but his address is also requested action is in line with struts blocking rules , and even a little wrong parameters , OH, MY GOD
------ For reference only ---------------------------------------




parameters of the problem , after all, still and scattered it, but the trigger is a bit more special

EL expression $ {} nesting

Originally Direct $ {user.id} can get the value ,
But now I get from the database the User property of the presence of a variable inside $ {fid} = id $ {fname} = name
$ {user. $ {fid}} Do not do that . .

Will this situation how to do it ?
------ Solution ---------------------------------------- ----
looks like it can not be nested . Why would you do it ? In order to achieve loose coupling do ? It is not necessary .
------ Solution ---------------------------------------- ----
$ {user.fid}

or

$ {user ["fid"]}
------ Solution -------------------------- ------------------
Map map
# {user.map ['abc']}
------ Solution ------------------------- -------------------
LZ, do you want the interface to get the User 's ID? Can understand the point of your question . ( My User properties from the database to obtain the presence of a variable inside )
------ Solution -------------------------- ------------------


I looked back and forth several times , he just did not know what LZ want to achieve ?
------ Solution ---------------------------------------- ----
it is not, first use a variable to store , and then PageContext.getAttribute () and then taken out
------ For reference only ------------ ---------------------------

there is a need to control the page display fields. . . So to this
------ For reference only ----------------------------------- ----

not do so directly . It will be reported Property 'fid' not found on type com.entity.User
------ For reference only ------------- --------------------------

amount . . Just tried it or not eh . . Hey ~
------ For reference only ---------------------------------- -----

amount .. there is a User ID, ​​name these two properties , and now I'm not sure I want to show that field , so to check the database is to show ID or name. query results in a variable inside .. $ {fid} = id or $ {fname} = name;
interface shows how $ {user.name} = 'xx' now use $ {fname} instead of name $ {user. $ {fname}} ( Of course, this does not work ) . . .
------ For reference only -------------------------------------- -

. . . . . I can express myself so unclear ? Is to user.id the user id and the two variables were placed inside, and then how assembled into $ {user.id} this effect. . .
------ For reference only -------------------------------------- -
landlord should say , in dynamic properties of the user to take out
------ For reference only ------------------- --------------------
I finally understand the meaning of the landlord
because I also encountered this problem

tried many ways and finally get

Using struts-bean.tld "prefix =" bean "%>

perfect solution

Being studied abroad java, foreigners topic , seeking guidance , has been translated

 This post last edited by the u011808925 on 2013-09-24 18:59:46
Problem Description and background
In a distant star systems, planets Pern has been human settlement . Pern every 200 years or so, the theme of distress. Theme and fall through the atmosphere from outer space . If the meteorite reaches the ground , it will destroy the plants and animals ( including humans ) . People of Pern fire-breathing dragons, human ridden. When the subject falls dragons and riders up into the air, and try to destroy theme, before reaching the ground . If the patch dragon theme is close enough , then it's flames completely destroyed theme.

dragons come in different sizes , which is based on the color of the dragon . Larger dragons have a larger wingspan , which means that they can go and fall faster than the little dragon. However, the greater dragons do not go left or right, and smaller dragons.

bigger dragon also have a stronger flame , which means they can be further away from the subject, when they tried to destroy it , than small dragon, still successful.

This is called flame distance.

When meteorites began to decline , Dragons and riders know that the topic has been started to decline , but they do not know exactly where . Therefore , the dragon begins somewhere in the sky . When the location of the dragon and rider meteorite , then they must attempt to fly themed locations.

subject location record can be used , such as two coordinates , X1, and Y1. x1 (horizontal ) coordinates from some arbitrary point on the ground distance ( positive or negative ) . Y1 ( vertical ) axis is the height above the ground .

with two coordinates , X2 and Y2, such as the location of the dragon is also recorded . 2 X ( horizontal ) coordinates are from the same arbitrary point on the ground a distance ( positive or negative ) for the thread . Y2 ( vertical ) axis is the height above the ground dragon .

flights in lawsuits theme is divided into time slots. In a time slice , thread fell 100 units , or blow to the left or to the right level of 100 units . When the dragon for menu selection , which has continued for the entire time slice .

± represent plus or minus

Long to go left or right to use this formula at the end = oldX ± ((100 / wingspan ) * 50 )
left, so that the end is less than oldX , so less of it to end more than oldX plus

Note: X can be negative

all dragons go up or down using this formula newY a = oldY ± ( wingspan * 5 )
dragon never crashed to the ground , their land , so if it is a negative newY zero
formula for the distance between two points is the distance = √ (× 2 - × 1) 2 + (Y2 - yl ) ; 2

theme may go up or down, left or right.

explained below , is the random decision.

theme of the work to the next location .

generates a random number between 0 and 16 ( exclusive )

If the random number is 0, 1 , 3 or 11
Then , the new x1 ( horizontal ) position of the theme is 100 units to the right . Y1 ( vertical direction ) position remains unchanged.

If the random number is 5, 9 or 14
Then , the new x1 ( horizontal ) position is 100 units left-hand thread . Y1 ( vertical direction ) position remains unchanged.

any other number, in addition to those above mean
Y1 ( vertical position ) theme is 100 units , down X1 ( horizontal ) position remains unchanged.

Program Requirements

you need to write a program in Java , Analog dragon and rider trying to destroy theme.

The program starts reading the values ​​from a text file . Section 6 of the text file format. You can assume that the text file is always correct , the correct format . Your program must not hard -coded input file name. That is , your program must be in the correct format and any text file .

values ​​in the text file is stored in a local variable , one for each line of the input file in , see page 6 for a complete explanation.

Then , the generated initial position of the thread .

x1 of ( horizontal ) position 0 and 4000 generated random number between ( not included )

Y1 ( vertical direction) position of the generated random number between 1000 and 2000 ( not included)

In the text file is read , and generates the initial position of a meteorite , the user is presented a menu. Then the user to enter commands until either succeeded in destroying the dragon theme , the theme reaches the ground or the user to enter the " exit " command

command must be case-insensitive. This means that the left and left commands
must have the same result.

Shown below is an example of the menu ( note that you can customize the menu , but the input of commands that must be a text , and must be able to handle more than one word commands )

menu

Left - Left - Right to go up -
- down
flame - breathing fire between - between the exit
input selection >>

can enter commands and explanations of each command

leave

If you enter this command , the new X2 ( horizontal ) position of the dragon had used a formula , the first three . Long Y2 ( vertical ) position remains unchanged . Please note that the new location will be lower than the old X2 X2 position .

Right

If you enter this command , the new X2 ( horizontal ) position of the dragon had used a formula , the first three . Long Y2 ( vertical ) position remains unchanged . Please note that the new location will be larger than the old X2 X2 position .

on

If you enter this command , then the new Y2 ( vertical ) position of the dragon
using the formula on page 3 . Long X2 ( horizontal) position remains unchanged. Note that the new position will be greater than the old Y2 Y2 locations.

next

If you enter this command , then the new Y2 ( vertical ) position of the dragon
using the formula on page 3 . Long X2 ( horizontal) position remains unchanged. Please note the new location will be lower than the old Y2 Y2 position .

Fire

If you enter this command , then the work of the dragon and the theme is the distance between two points using the first three distances between formulas.
If the distance is less than or equal to the distance of the dragon's flame , then meteorite is destroyed , the corresponding message ( including the name and color of the dragon ) is output to the screen and close the program.

If the distance is greater than the distance from the flame , then the corresponding display information output to the screen, is not destroyed themes guide the user . Program execution continues .

This menu selection does not change the position of the dragon . If the meteorite is not destroyed, and then calculate the new position subject , but Long
remain in the same position .
between


If you enter this command , then the dragon 'between' this time slice . This means that the dragon's position does not change. Subject new location, but calculated .

Tip: This is a very useful command , if the dragon is in the correct position ( horizontal ) , but above the dragon theme , but the flame distance. Dragon 'between' , come back in exactly the same position and topics
has dropped close to Long . Of course, the thread may be blown to the left or right , rather than between the dragon .

exit

If you enter this command, the program ends , the message is not displayed meteorite is being destroyed.

Note : System.exit () is not allowed, the use will result in any significant loss of marks .

program continues to loop around until destroyed themes, themes reach the ground, two cases in which the corresponding message
( including the name and color of the dragon ) is output to the screen , the user enters " quit " command.


Each time through the loop is considered to be a time slice .

Each time through the loop , themes and Long positions should be shown on the screen.

input text file format

line in the file description
Mnementh Long Name
39 Wingspan (INT)
Benden weyr ( can be more than one word )
color bronze dragon
1000 initial Y2 position ( height ) of the Dragon
2000年2 times the initial ( horizontal ) position of the Dragon
200 Flame Long distance

attached below the original English edition

Problem Description and Background
The planet Pern, in a faraway star system, has been settled by humans. Every 200 years or so, Pern is plagued by Thread. Thread comes from outer space and falls through the atmosphere. If Thread reaches the ground then it destroys plants and animals (including humans). The people of Pern have fire breathing dragons, ridden by humans. When Thread falls the dragons and riders rise up into the air and attempt to destroy the Thread before it reaches the ground. If a dragon is close enough to a patch of Thread then its flame completely destroys the Thread.

Dragons come in different sizes, this is based on the colour of the dragon. Bigger dragons have a bigger wingspan which means that they can go up and down faster than smaller dragons. However bigger dragons don't go left or right as well as smaller dragons.

Bigger dragons also have a stronger flame which means they can be further away from Thread when they attempt to destroy it, than smaller dragons, and still succeed.

This is known as the flame distance.

When Thread starts to fall the Dragons (and riders) know that Thread has started to fall, but they don't know ; exactly where. So the dragon starts at a certain location in the sky. When the dragon and rider see the position of the ; Thread then they have to try and fly to the position of the Thread.

The position of Thread is recorded using two co-ordinates, x1 and y1, for example. The x1 (horizontal) coordinate ; is the distance (plus or minus) from some arbitrary point on the ground. The y1 (vertical) coordinate is the height above ; the ground.

The position of the dragon is also recorded using two coordinates, x2 and y2, for example. The x2 (horizontal) ; coordinate is the distance (plus or minus) from the same arbitrary point on the ground as is used for Thread. The y2 (vertical) coordinate is the height of the dragon above the ground.

In the action against Thread the flight is divided up into time slices. In one time slice, Thread falls 100 units or is blown horizontally 100 units left or right. When a dragon carries out a menu choice, this also lasts for the whole time slice.

± means plus or minus

All dragons go left or right using this formula newX = oldX ± ((100 / wingspan) * 50)
to go left makes newX less than oldX so subtract to go right makes newX greater than oldX so add

NOTE: x can be negative

All dragons go up or down using this formula newY = oldY ± (wingspan * 5)
Dragons never crash into the ground, they land, so if newY is negative make it zero
The formula for working out the distance between 2 points is distance = √ (x2 - x1) 2 + (y2 - y1) 2

Thread can go down, left or right.

This is determined randomly which is explained below.

Working out the next position of Thread.

Generate a random number between 0 and 16 (exclusive)

If the random number is 0, 3 or 11
then the new x1 (horizontal) position of Thread is 100 units to the right. the y1 (vertical) position stays the same.

If the random number is 5, 9 or 14
then the new x1 (horizontal) position of Thread is 100 units to the left. the y1 (vertical) position stays the same.

any other number except the ones above means that
the y1 (vertical) position of the Thread is 100 units down the x1 (horizontal) position stays the same.

Program Requirements

You are required to write a program, in Java, to simulate a dragon and rider trying to destroy Thread.

The program starts by reading in values ​​from a text file. The format of the text file is given on page 6. You may assume that the text file is always correct and in the correct format. Your program must not hard code the name of the input file. That is, your program must work with any text file in the correct format.

The values ​​in the text file are stored in local variables, one for each line of the file input, see page 6 for the full explanation.

Then the initial position of Thread is generated.

The x1 (horizontal) position is generated by a random number between 0 and 4000 (exclusive)

The y1 (vertical) position is generated by a random number between 1000 and 2000 (exclusive)

After the text file is read in, and the initial position of Thread is generated, the user is presented with a menu. The user then enters commands until the dragon either successfully destroys Thread, Thread reaches the ground or the user enters the " quit "command

Commands must be case insensitive. That means that the commands lefT and LEft
must have the same result.

Shown below is an example of the menu (note, you can customize the menu, but the commands that are entered must ; be text, and must be able to handle a command of more than one word)

Menu

left - Go left right - Go right up - Go up
down - Go down
flame on - breathe fire between - go between quit
Enter choice >>

Commands that can be entered and an explanation of each command

left

If the user enters this command, then the new x2 (horizontal) position of the dragon is worked out using the formula ; on page 3. The y2 (vertical) position of the dragon remains the same. Note that the new x2 position will be less than the old x2 position.

right

If the user enters this command, then the new x2 (horizontal) position of the dragon is worked out using the formula ; on page 3. The y2 (vertical) position of the dragon remains the same. Note that the new x2 position will be greater than the old x2 position.

up

If the user enters this command, then the new y2 (vertical) position of the dragon
is worked out using the formula on page 3. The x2 (horizontal) position of the dragon remains the same. Note ; that the new y2 position will be greater than the old y2 position.

down

If the user enters this command, then the new y2 (vertical) position of the dragon
is worked out using the formula on page 3. The x2 (horizontal) position of the dragon remains the same. Note ; that the new y2 position will be less than the old y2 position.

flame on

If the user enters this command, then the distance between the dragon and Thread is worked out using the formula for the distance between 2 points on page 3.
If this distance is less than or equal to the flame distance of the dragon, then the Thread is destroyed, an appropriate message (which includes the name and colour of the dragon) is output to the screen and the program closes.

If the distance is greater than the flame distance then an appropriate message is output to the screen advising the user that the Thread was not destroyed. The program continues.

This menu choice does NOT change the position of the dragon. If Thread is not destroyed then the new position of Thread is calculated, but the dragon
stays in the same position.

between

If the user enters this command then the dragon "goes between" for this time slice. This means that the position of the dragon does not change. The new position of Thread is, however, calculated.

Hint: this command is useful if a dragon is in the right position (horizontally) but Thread is above the dragon, ; but out of flame distance range. The dragon can "go between", come back in exactly the same position and Thread will
have dropped down closer to the dragon. Of course, Thread may be blown left or right instead of going down while the dragon was between.

quit

If the user enters this command, the program ends, without displaying a message about whether or not Thread was destroyed.






------ Solution ------------------------------------ --------
me that all watching . Thread I do not know what should be translated into ? Know and what I say next .

I probably said that under the background of it, is to have a Thread that fell outside of Pern from the atmosphere on the planet , and then people on Pern has a very fast hardware mounts, fire-breathing dragon ( Nima really fast hardware ) . Then they 'll ride this fire-breathing dragon to go to Thread melt away , fell to the ground before the Thread .

procedures require that a console input commands manipulate virtual dragon to melt Thread. Each instruction is mainly for the operation coordinate what quantity .
not clear in some places that look page6, there should be a book . Electronic files should all foreign materials, you only made one such request , others simply can not help you .

Ps: I was more bored, so a reading article. . . Landlord, if it will not do, add my QQ bar. 392190627 . Studying abroad is really not easy.
------ For reference only -------------------------------------- -
amount . . . Good looks complicated , it will not, and continue to onlookers !
------ For reference only ---------------------------------------
can not use google translate it ?
------ For reference only -------------------------------------- -
less playing the Three Kingdoms , see more java, will write a
------ For reference only -------------------- -------------------
Well, to see such a long title , I was directly pull the scroll bar
------ For reference only ---------------------------------------
this translation is a good one. . .
------ For reference only -------------------------------------- -
you do not learn Java Yes, even these students go abroad every Google Translate English what kind of strength is also mixed .
------ For reference only -------------------------------------- -
Why Chinese version but can not see understand. . .
------ For reference only -------------------------------------- -
FML , this Chinese Translator ... I ... I started to feel very smooth in English
------ For reference only ---------------------------------------
 English. .
------ For reference only -------------------------------------- -
  The reply deleted by an administrator at 2013-09-25 10:16:13

------ For reference only ---------------------------------- -----
this translation . .
------ For reference only ---------------------------------------
said that did not understand, do not bother Kane.
------ For reference only -------------------------------------- -
  The reply deleted by an administrator at 2013-09-25 16:33:36

------ For reference only ---------------------------------- -----
indicates that the content for a long ~
------ For reference only ------------------------- --------------
this is the game you ?
------ For reference only -------------------------------------- -

---- - For reference only ---------------------------------------
Tete Mody long +
------ For reference only ----------------------------------- ----

- ----- For reference only ---------------------------------------

Chinese , English can not read how to do , a quick look at the story as
------ For reference only --------------- ------------------------
English no, Chinese do not understand
------ For reference only --------------------- ------------------
you Ah ah ass with a software translator
------ For reference only -------- -------------------------------
this is God horse stuff , ah, too deep right
- ---- For reference only ---------------------------------------
< br /> you're bored. . . Another Thread proposal transliterated as " feces come "
------ For reference only ---------------------------- -----------

you really boring. . . Another Thread proposal transliterated as " feces come ."  
disgusting . .
------ For reference only ---------------------------------------
good fast hardware , a good high-end like ah
------ For reference only ------------------------------------ ---
English lot, Mo Kanwan . Chinese Good complicated read.
------ For reference only -------------------------------------- -
abroad flow problem is to force ! !
------ For reference only -------------------------------------- -
this Chinese translation has been through six orifices ! really powerful

Why 127 +1 is equal to -128

the java byte data range is -128 to 127 ; Why -128-1 will be equal to 127 ; 127 +1 and equal to -128 of it ? Counted in the end how ah ?
------ Solution ---------------------------------------- ----
byte length is 8 bits, the leftmost bit is the sign bit
127 binary : 01111111
-1 binary : 1111 1111 , plus an all-zero ,
-2 Binary : 1111 1110
......
-128 binary : 10000000

thus 127 +1 = -128
------ Solution --------------------------- -----------------
java byte type for the calculation will be converted to an int and then calculate .
example
byte b = 127 + 1 ;/ / write error : Type mismatch: cannot convert from int to byte
so you must cast :
byte b = (byte) (127 + 1);

So you can understand why it is -128 of :
int type 127 in the computer 's binary:
0000 0000 0000 0000 0000 0000 0111 1111
plus 1 becomes:
0000 0000 0000 0000 0000 0000 1000 0000
namely 128
interception after coercion becomes low 8
1000 0000
This is the complement of byte type -128 .
------ Solution ---------------------------------------- ----
hope you're using win7, open the attachment inside the calculator. View > Programmers

following number keys on the left , the decimal and byte
input 127 , you can see the bottom of the binary numbers
0111 1111 +1
Then , you will see a normal into a binary
1000 0000,
but the display is -128

because the most significant bit is the sign bit
------ Solution ------------------------------ --------------
data overflow , byte a byte 8 to only save , 256 numbers , byte from -128 to +127 ,
biggest plus > a few will be data overflow , the smallest minus > 1 will overflow.
127 +1 = -128;
127 +2 = - 127;
127 +3 = -126;

-128 - 1 = 127;
Not only is byte type , short, int, long, float, double data will overflow . In fact, very good 5th floor of the analysis .
------ For reference only -------------------------------------- -
overflow ! Maximum int + 1 = smallest int
------ For reference only ----------------------- ----------------
this is the overflow of a binary addition and subtraction problems
------ For reference only ---------- -----------------------------
support

------ For reference only ---------------------------------- -----
upstairs talking to is very detailed , byte byte representing 8 , 127 +1 to overflow , computer operations, in order to complement the form of running , the front one is the sign bit , so it becomes -128 a
------ For reference only ----------------------------- ----------
+1
------ For reference only ----------------------- ----------------
first statement is that you are sure of type byte , then byte length is 8 , the leftmost bit is the sign bit , 0 is a positive number , a negative
127:0111 1111
0: 0000 0001
sum : 10000000
then to understand that the first one is a negative, complement his abs = +1 , which is 01111111 +0000 0001 128 , so the final result is -128
---- - For reference only ---------------------------------------
above you says is the original code in addition and subtraction , the computer calculations are carried out between the original code , or twos complement arithmetic between ah ? ? Thank you
------ For reference only ------------------------------------ ---
computer composition principle did not learn
------ For reference only --------------------------- ------------

computer where is complement
you carefully understand the original code calculations and by complement calculations are the same, because the last stored in the computer are the complement.
------ For reference only -------------------------------------- -
127 binary : 01111111

-128 binary : 1000 0000
------ For reference only -------------------------- -------------
127 +1 = -128
This problem has already said very clearly the fifth floor

As for why -128-1 = 127
reasons:
-128:1000 0000
1:0000 0001
As for the concept of variable compensation , go check it
So:
-128 +1 Variable compensation :
1000 0000
1111 1111
Results:
10111 1111
take the top eight 01111111 = 127

------ For reference only ---------------------------------- -----
overflow problem ! Upstairs is very clear !
------ For reference only -------------------------------------- -
public class Demobyte {

/ **
* @ param args
* /
public static void main (String [] args) {
byte a = 127;
byte b = 1;
byte c = (byte) (b + a) ;/ / -128
/ / byte operand of type float and double if not yo inside arithmetic operations are of type int , then then cast into a byte type
System.out.println (c);
byte d = -1;
byte e = -128;
byte f = (byte) (d + e) ​​;/ / 127
System.out.println (f);
}

}


upstairs that's good . . is this if there is no float and double is converted to int op . . reckon after cast to byte! !
------ For reference only -------------------------------------- -

Dude , that can help explain -127-128 do ? Why result will be a
-127: 1111 1111
+
-128: 1000 0000
If If truncation , then, is not
= 127 0111 1111
but the result is one yet. So if I understand

-128 1000 0000 minus 127
-
127 0111 1111
= 1 0000 0001
this case is a the trouble to explain it

struts2 redirect transmission parameters of the problem .




// struts2 重定向 传参数问题。
<action name="addInfo" class="infoAction" method="add">

  <result name="success" type="redirectAction">

                 <param name="actionName">listInfo</param>

                 <param name=" ">${info.id}</param>

                 <param name=" ">${info.title}</param>

             </result>           //param name=" "应该怎么填写?

</action>


<action name="listInfo" class="infoAction" method="list">

<result name="success">/infolist.jsp</result>

</action>


//infolist.jsp

<s:iterator id="c" value="infos" status="s">

<s:property value="id" /> //id是自增的,别说用转发 type=chain

​<s:property value="title" />

</s:iterator>


------ Solution ------------------------------------- -------


you put your own needs to think clearly , to redirect queries need to add data transfer over you ? Pass in the past is really useful ? The data do you use to add a list of query parameters?

If you must pass, direct
****. action? info.id = $ {info.id} & info.name = $ {info.name}

------ Solution - -------------------------------------------
do you want to use in such a way to achieve it, you just want to add is successful, the listinfo page and then flew just added successfully traverse the data is right, then you first add it again without success after the investigation would be finished . . . .
------ For reference only -------------------------------------- -
landlord does not know what the intention is , why you wrote . If you really do not know to look struts-config.xml file , strut2 underlying Which constants related with this approach , like that actionName is how come the same !!!
------ For reference only - --------------------------------------


My intention is clear ah , click Save execute addInfo.Action. Yet addInfo redirected to listInfo all data that is traversing . But is stuck in this step do not know what this fill , try a variety of results did not solve .
------ For reference only -------------------------------------- -
/ / param name = "" how should I fill out ? parameter names , is that you need to define , and then in the action (infoAction) define and generate parameter set, get method, then you can directly access the parameter value via the parameter



------ For reference only ---------------------------------- -----
this need not redirect directly in the add method in the finish after their own logic to the info assignment , result write
/ infolist.jsp
------ For reference only -------------- -------------------------

action is defined objects , collections, no attributes , attribute separately defined in the entity class medium . That at this time / / param name = "" should be how to fill ? Or in the action must be written on the id title attribute get set way to do this ?

------ For reference only ---------------------------------- -----
representation never knew this kind of approach , novice !
------ For reference only ---------------------------------------


You did not understand what I mean, fill in the page data is complete, click the button to perform this action when addInfo will be redirected to listInfo. The problem is to redirect / / param name = "" what to write ? .
------ For reference only -------------------------------------- -

  
You did not understand what I mean, fill in the page data is complete, click the button to perform this action when addInfo will be redirected to listInfo. The problem is to redirect / / param name = "" what to write ? .   course listInfo is to traverse all the data that is added after completion redirected to traverse the data page.
------ For reference only -------------------------------------- -

action is defined objects , collections, no attributes , attribute separately defined in the entity class. That at this time / / param name = "" should be how to fill ? Or in the action must be written on the id title attribute get set way to do this ?   
 

parameter names can be arbitrarily defined , has also been defined sid, stitle, general, or define meaningful . You always want to touch hands . Do not be afraid , things are playing out ,
------ For reference only ---------------------------- -----------

<param name="info.id">${info.id}</param>
<param name="info.title">${info.title}</param> 

------ For reference only --------------------- ------------------
indicates weakness ah ~ ~ ~ ~
------ For reference only ---------------------------------------

this way wrong.
------ For reference only ---------------------------------------
10 floor impossible wrong , to make the $ {info.id} has a value , you must add a set method for the info object , you must have it to get the value of the get method , you see how to do ,
------ For reference only ---------------------------------------

  
you put your own needs to think clearly , to redirect queries need to add data transfer over you ? Pass in the past is really useful ? The data do you use to add a list of query parameters?   
  
If you must pass, direct   
****. action? info.id = $ {info.id} & info.name = $ {info.name}   
 
Thank you, big brother to the reminder , thought, after adding data does not need to redirect page spread list , I encountered a problem , add the data and click the Save page jump list , but added pages have a primary key auto-incremented ID, how to spread the list page .
with type = chain not, but after I click save , on the current page , and then click Connect to list page traverse action can get increment ID, but so unfriendly .
------ For reference only -------------------------------------- -
solve the problem, add a method to return the struts return list () method that is able to get the database traversal ID, but why add the action in struts.xml I wrote type = chain jumps to list the action, why not get the ID , I do not know why.

Help on how to use JSTL FOR loop

As the following code :
int num = 10;
for (int i = 0; i println (i);
}
how to use JSTL implementation ~ ~ Thank you prawn
------ Solution -------------------------- ------------------

<c:forEach var="item" varStatus="status" begin="1" end="10">
  ${status.index}
</c:forEach>

------ Solution ---------------- ----------------------------



$ {id.value} / / var here to write the above identification , id. / / arguments behind it , the entity ( the entity class entity )

------ Solution ----------------------------- ---------------
<%
int num = 10;
for (int i = 0; i %>
out.println (num);
<%

}
%>
This can
------ For reference only ------------------------------- --------
on the second floor of Positive Solutions
------ For reference only ------------------------ ---------------
upstairs positive solution . . . C tag with the EL with easy
------ For reference only ------------------------------- --------
  This reply was moderator deleted at 2012-04-05 10:40:16

------ For reference only ---------------------------------- -----


easiest is jstl
------ For reference only ----------------------------- ----------
2 Floor positive solution
------ For reference only ---------------------- -----------------

Thank you, brothers , EL fail to realize the FOR loop , only this realization ~ ~
------ For reference only ---------------------------------------
thank you
------ For reference only --------------------------------------- < br> $ {i}

Mid-Autumn Festival holiday, continued scattered points


------ Solution - -------------------------------------------

------ Solution ----- ---------------------------------------
continued access points , Autumn Festival .
------ Solution ---------------------------------------- ----

- ----- Solution --------------------------------------------

----- - Solution --------------------------------------------
< img src = "http://forum.csdn.net/PointForum/ui/scripts/csdn/Plugin/003/monkey/26.gif" alt = "" />
------ Solution - ------------------------------------------

------ Solution ------ --------------------------------------
two
------ Solution - -------------------------------------------

------ Solution ----- ---------------------------------------
good landlord . .
------ Solution ---------------------------------------- ----
points it
------ Solution ------------------------------------------ -

--- --- Solution --------------------------------------------
good landlord , I'll pick points, ,
------ Solution - -------------------------------------------

------ Solution ----- ---------------------------------------
Wow then tap points ;
------ Solution - -------------------------------------------

------ Solution ----- ---------------------------------------

------ Solution --------- -----------------------------------
tentatively second believe it. . .
------ Solution ---------------------------------------- ----
Thank landlord ,
------ Solution - -------------------------------------------

------ Solution ----- ---------------------------------------

------ For reference only ------- --------------------------------
 from the top one
------ For reference only ----------- ----------------------------
continue from the top , the points given to more people. . . .
------ For reference only ---------------------------------------
how ? Afraid brother do not give you points ah ? ? ?
------ For reference only ---------------------------------------

About jsp using js problem ? Solving



username:

password:

repassword:




Why this program can not succeed ah

import java.applet. *;
import java.awt. *;
import java.awt.event. *;
public class leapyear extends Applet implements ActionListener
{
Label result;
TextField inl;
Button btn;
int year;
boolean leap;
public void init ()
{
result = new Label (" Please enter the number to determine the year " ) ;
inl = new TextField (5);
add (inl);
add (btn);
add (result);
btn.addActionListener (this);
}
public void actionPerformed (ActionEvent e)
{
year = Integer.parseInt (inl.getText ());
if (year% 4! = 0)
leap = false;
else if (year% 100! = 0)
leap = true;
else if (year% 400! = 0)
leap = false;
else
leap = true;
if (leap == true)
result.setText (year + " is a leap year " ) ;
else
result.setText (year + " not a leap year " ) ;
inl.setText ("");
}
}

------ Solution ------------------------------------ --------
understand java -based Friends of the roof to help
estimate is junk code
------ Solution - -------------------------------------------
class name initials why is lowercase ?


------ Solution ------------------------------------ --------
In addition, this program where you are unsuccessful up ?
------ Solution ---------------------------------------- ----
said no public static void main (String arg []) can not run the main method . . . .  

public static void main ( String [] args )
------ For reference only -------- -------------------------------
white excited. . . I thought I solved it
------ For reference only -------------------------------- -------
said no public static void main (String arg []) can not run the main method . . . .
------ For reference only -------------------------------------- -
I tried . . . I still ah
------ For reference only ----------------------------------- ----
said no public static void main (String arg []) can not run the main method . . . .
------ For reference only -------------------------------------- -
to a main method .

An array of cross-border issues

Error code is as follows:
Scanner in = new Scanner (System.in);
System.out.println (" Please enter the first sequence of length : " ) ;
int m = in.nextInt ();
char [] array = new char [m];
System.out.println (" Please enter the first sequence : " )
for (int i = 0; i array [i] = in.nextLine (). charAt (0);


---------------------------------------------- ----------------------------------
The result:
Enter the length of the first sequence :
5
Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt (Unknown Source)


I novice , seeking god Weapon
------ Solution ----------------------------- ---------------

import java.util.*;

public class Test {
public static void main(String[] args) {
Scanner in=new Scanner(System.in);
System.out.println("请输入第一个序列的长度:");
int m=in.nextInt();
char []array=new char[m];
        System.out.println("请输入第一个序列:");
in.nextLine(); // 加入这句话 就可以了
for(int i=0;i<m;i++)
array[i]=in.nextLine().charAt(0);
}
}

You can look this article
http://blog.163.com/hellojavaj_v_m/blog/static/22553207720138811407968/
------ Solution -------------------------------------- ------
nextInt () Return will be entered after the first nextLine () capture
------ For reference only ------------ ---------------------------
length of the array is fixed and must be initialized
--- --- For reference only ---------------------------------------
in. nextLine () is an empty string , right

------ For reference only ---------------------------------- -----
in.nextLine (). charAt (0) there are problems
------ For reference only ------------------ ---------------------

+1
------ For reference only -------- -------------------------------



ah , thank
------ For reference only ------------------------------- --------


So that

java package into your question

In a recent study found that some of the classes final modification java.lang used , without introducing package name , is not modified with the final class , not duplicate, can not be rewritten, it can be directly used , and that the bag with the other final modification is the introduction of package may not directly use it ? New learning , please guide , thank you !
------ Solution ---------------------------------------- ----
java.lang are not under the guidelines, the default has been introduced
------ Solution -------------------- ------------------------
lang package under the No, the other was the introduction of
------ Solution --- -----------------------------------------
+1

getServletContext (). getAttribute () type conversion issues



<%
String aname = null;
String avalue = null;
Enumeration enu = this.getServletContext (). getAttributeNames ();
while (enu.hasMoreElements ())
{
aname = (String) enu.nextElement ();
avalue = (String) getServletContext (). getAttribute (aname);
%>
<% = aname%> -----> <% = avalue%>

<%
}
%>

SSH2 build the framework of the exception , I have added the jar package , an error was thrown NoClassDefFoundError, seeking god help !

2013-9-26 15:18:32 org.apache.catalina.core.AprLifecycleListener init
Information : The APR based Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library. path: D: \ myeclipse9.0 \ Common \ binary \ com.sun.java.jdk.win32.x86_1.6.0.013 \ bin; D: \ tomcat7.0.2 \ bin
2013-9-26 15:18:32 org.apache.coyote.http11.Http11Protocol init
Information : Initializing Coyote HTTP/1.1 on http-8888
2013-9-26 15:18:32 org.apache.coyote.ajp.AjpProtocol init
Information : Initializing Coyote AJP/1.3 on ajp-8009
2013-9-26 15:18:32 org.apache.catalina.startup.Catalina load
Information : Initialization processed in 391 ms
2013-9-26 15:18:32 org.apache.catalina.core.StandardService startInternal
Information : Starting service Catalina
2013-9-26 15:18:32 org.apache.catalina.core.StandardEngine startInternal
Information : Starting Servlet Engine: Apache Tomcat/7.0.2
2013-9-26 15:18:32 org.apache.catalina.startup.HostConfig deployDirectory
Information : Deploying web application directory docs
2013-9-26 15:18:32 org.apache.catalina.startup.HostConfig deployDirectory
Information : Deploying web application directory examples
2013-9-26 15:18:32 org.apache.catalina.core.ApplicationContext log
Information : ContextListener: contextInitialized ()
2013-9-26 15:18:32 org.apache.catalina.core.ApplicationContext log
Information : SessionListener: contextInitialized ()
2013-9-26 15:18:32 org.apache.catalina.startup.HostConfig deployDirectory
Information : Deploying web application directory host-manager
2013-9-26 15:18:32 org.apache.catalina.startup.HostConfig deployDirectory
Information : Deploying web application directory manager
2013-9-26 15:18:32 org.apache.catalina.startup.HostConfig deployDirectory
Information : Deploying web application directory ROOT
2013-9-26 15:18:32 org.apache.catalina.startup.HostConfig deployDirectory
Information : Deploying web application directory School
2013-9-26 15:18:33 org.apache.catalina.core.ApplicationContext log
Information : Initializing Spring root WebApplicationContext
log4j: WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j: WARN Please initialize the log4j system properly.
2013-9-26 15:18:33 org.apache.catalina.core.StandardContext listenerStart
Serious : Exception sending context initialized event to listener instance of class org.springframework.web.context.ContextLoaderListener
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'ProxyCreator' defined in ServletContext resource [/ WEB-INF/beans.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator ]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org / aopalliance / intercept / MethodInterceptor
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean (AbstractAutowireCapableBeanFactory.java: 1007)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance (AbstractAutowireCapableBeanFactory.java: 953)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean (AbstractAutowireCapableBeanFactory.java: 487)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean (AbstractAutowireCapableBeanFactory.java: 458)
at org.springframework.beans.factory.support.AbstractBeanFactory $ 1.getObject (AbstractBeanFactory.java: 295)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton (DefaultSingletonBeanRegistry.java: 223)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean (AbstractBeanFactory.java: 292)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean (AbstractBeanFactory.java: 198)
at org.springframework.context.support.AbstractApplicationContext.registerBeanPostProcessors (AbstractApplicationContext.java: 741)
at org.springframework.context.support.AbstractApplicationContext.refresh (AbstractApplicationContext.java: 464)
at org.springframework.web.context.ContextLoader.configureAndRefreshWebApplicationContext (ContextLoader.java: 389)
at org.springframework.web.context.ContextLoader.initWebApplicationContext (ContextLoader.java: 294)
at org.springframework.web.context.ContextLoaderListener.contextInitialized (ContextLoaderListener.java: 112)
at org.apache.catalina.core.StandardContext.listenerStart (StandardContext.java: 4323)
at org.apache.catalina.core.StandardContext.startInternal (StandardContext.java: 4780)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java: 139)
at org.apache.catalina.core.ContainerBase.addChildInternal (ContainerBase.java: 785)
at org.apache.catalina.core.ContainerBase.addChild (ContainerBase.java: 763)
at org.apache.catalina.core.StandardHost.addChild (StandardHost.java: 557)
at org.apache.catalina.startup.HostConfig.deployDirectory (HostConfig.java: 1124)
at org.apache.catalina.startup.HostConfig.deployDirectories (HostConfig.java: 1047)
at org.apache.catalina.startup.HostConfig.deployApps (HostConfig.java: 542)
at org.apache.catalina.startup.HostConfig.start (HostConfig.java: 1390)
at org.apache.catalina.startup.HostConfig.lifecycleEvent (HostConfig.java: 355)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent (LifecycleSupport.java: 119)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent (LifecycleBase.java: 89)
at org.apache.catalina.util.LifecycleBase.setState (LifecycleBase.java: 313)
at org.apache.catalina.util.LifecycleBase.setState (LifecycleBase.java: 293)
at org.apache.catalina.core.ContainerBase.startInternal (ContainerBase.java: 996)
at org.apache.catalina.core.StandardHost.startInternal (StandardHost.java: 771)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java: 139)
at org.apache.catalina.core.ContainerBase.startInternal (ContainerBase.java: 988)
at org.apache.catalina.core.StandardEngine.startInternal (StandardEngine.java: 275)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java: 139)
at org.apache.catalina.core.StandardService.startInternal (StandardService.java: 427)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java: 139)
at org.apache.catalina.core.StandardServer.startInternal (StandardServer.java: 649)
at org.apache.catalina.util.LifecycleBase.start (LifecycleBase.java: 139)
at org.apache.catalina.startup.Catalina.start (Catalina.java: 585)
at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java: 39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java: 25)
at java.lang.reflect.Method.invoke (Method.java: 597)
at org.apache.catalina.startup.Bootstrap.start (Bootstrap.java: 288)
at org.apache.catalina.startup.Bootstrap.main (Bootstrap.java: 415)
Caused by: org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org / aopalliance / intercept / MethodInterceptor
at org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java: 163)
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate (SimpleInstantiationStrategy.java: 87)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean (AbstractAutowireCapableBeanFactory.java: 1000)
... 44 more
Caused by: java.lang.NoClassDefFoundError: org / aopalliance / intercept / MethodInterceptor
at org.springframework.aop.framework.adapter.DefaultAdvisorAdapterRegistry. (DefaultAdvisorAdapterRegistry.java: 50)
at org.springframework.aop.framework.adapter.GlobalAdvisorAdapterRegistry. (GlobalAdvisorAdapterRegistry.java: 32)
at org.springframework.aop.framework.autoproxy.AbstractAutoProxyCreator. (AbstractAutoProxyCreator.java: 116)
at org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator. (BeanNameAutoProxyCreator.java: 46)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0 (Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance (NativeConstructorAccessorImpl.java: 39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance (DelegatingConstructorAccessorImpl.java: 27)
at java.lang.reflect.Constructor.newInstance (Constructor.java: 513)
at org.springframework.beans.BeanUtils.instantiateClass (BeanUtils.java: 148)
... 46 more
Caused by: java.lang.ClassNotFoundException: org.aopalliance.intercept.MethodInterceptor
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java: 1666)
at org.apache.catalina.loader.WebappClassLoader.loadClass (WebappClassLoader.java: 1511)
at java.lang.ClassLoader.loadClassInternal (ClassLoader.java: 320)
... 55 more
2013-9-26 15:18:33 org.apache.catalina.core.StandardContext startInternal
Serious : Error listenerStart
2013-9-26 15:18:33 org.apache.catalina.core.StandardContext startInternal
serious : Context [/ School] startup failed due to previous errors
2013-9-26 15:18:33 org.apache.catalina.core.ApplicationContext log
Information : Closing Spring root WebApplicationContext
log4j: WARN No appenders could be found for logger (org.springframework.web.context.ContextLoader).
log4j: WARN Please initialize the log4j system properly.
log4j: WARN No appenders could be found for logger (com.opensymphony.xwork2.config.providers.XmlConfigurationProvider).
log4j: WARN Please initialize the log4j system properly.

------ Solution ------------------------------------ --------
should be even less a aopalliance.jar
------ Solution --------------------- -----------------------
added yet determined to tomcat webapps next look at whether this package and then consider the next packet collisions is not it
------ Solution ----------------------------- ---------------
you add the finished package , added to the compiler environment yet ? If you add , that you try to delete a look at this package should be package conflict
------ Solution ------------------- -------------------------
to see if the cause of the conflict is the package ;
spring alt2.7
struts asm2.2.3

say this two pack removal
------ For reference only ---------------------------- -----------
aopalliance.jar I also added still the same error
org / aopalliance / intercept / MethodInterceptor this class can be found in spring.jar
Is not there is a conflict between the jar package ?

------ For reference only ---------------------------------- -----
what you use development tools
------ For reference only ------------------------ ---------------
I use myeclipse9, intended to use another version of the jar try again !

dom4j read xml file


public class xml2Instance {
public static void main(String[] args){
SAXReader reader = new SAXReader();

try {
Document doc =  reader.read
(new FileInputStream("C:/Users/Administrator/Desktop/first.xml"));
Element root = doc.getRootElement();
Customer customer = new Customer();
System.out.println(root.attributeValue("CustName"));
customer.setCustName(root.attributeValue("CustName"));
customer.setType(root.attributeValue("Type"));
customer.setDest(root.attributeValue("Dest"));
customer.setFlight(root.attributeValue("Flight"));
customer.setTime(root.attributeValue("Time"));

System.out.println(customer);


}
}


heroes , and why I can not read file values ​​, um, I was just using dom4j first.xml written , but it is there ah
which also display the content, for the thing at the time to read it will show null
?
------ Solution ----------------------------------- ---------
xml file you do not know what kind , but feel you should have no access to the outer Customer (); object
give you one example

public Map<String, String> getProvinceMap() {
Map<String, String> proMap = new HashMap<String, String>();
try {
InputStream in = DBHelper.getDBHelper().getContext().getResources()
.getAssets().open("province.xml");
InputStream is = IOHelper.fromInputStreamToInputStreamInCharset(in,"utf-8");
SAXReader sr = new SAXReader();// 获取读取xml的对象。
Document document = sr.read(is);
Element root = document.getRootElement();
List<?> elementlist = root.elements("city");
for (Object obj : elementlist) {
Element row = (Element) obj;
String quName = row.attribute("quName").getText();
String pyName = row.attribute("pyName").getText();
proMap.put(quName, pyName);
}
} catch (Exception e) {
Log.e("tag", "read configure error");
}
return proMap;
}



<?xml version="1.0" encoding="utf-8"?>
<china dn="day">
<city quName="黑龙江" pyName="heilongjiang" cityname="哈尔滨" state1="21" state2="7" stateDetailed="小到中雨转小雨" tem1="21" tem2="13" windState="东风4-5级转3-4级"/>
<city quName="吉林" pyName="jilin" cityname="长春" state1="8" state2="9" stateDetailed="中雨转大雨" tem1="19" tem2="14" windState="东南风3-4级"/>
<city quName="辽宁" pyName="liaoning" cityname="沈阳" state1="8" state2="9" stateDetailed="中雨转大雨" tem1="21" tem2="18" windState="东南风小于3级转3-4级"/>
</china>

------ For reference only ----------------------------------- ----
look first.xml content .

Class has no main method


package helloworldapp;

public class first
{
    class J_Employee
    {
        public int m_workYear;

        public J_Employee()
        {
            m_workYear = 1;
        }
    }

    public class J_Teacher extends J_Employee
    {
        public int m_classHour;

        public J_Teacher()
        {
            m_classHour = 96;
        }
        public void mb_printInfo()
        {
            System.out.println("该教师的工作年限为"+m_workYear);
            System.out.println("该教师的授课课时为"+m_classHour);
        }
        public static void main(String args[])
        {
            J_Teacher tom = new J_Teacher();
            tom.mb_printInfo();
        }
    }
    
}
Examples of books
What is wrong ? ? If the main place outside the class , does not work, seek solutions ! !
------ Solution ---------------------------------------- ----
landlord right main move out, and then changed to the following:

  public static void main(String args[])
    {
     PolymorphismTest pltt=new PolymorphismTest();
        PolymorphismTest.J_Teacher tom=pltt.new J_Teacher();
        tom.mb_printInfo();
    }

This should clearly know why the wrong bar ?
------ For reference only -------------------------------------- -
main (String args [])

should be String [] args
------ For reference only -------------------------- -------------
I prawn up ! !