2014年5月26日星期一

I have a good job shiro, after successful login, how to get user information in jsp page ?

I added shiro in the project, are equipped with a good

this time from the login page login, login is certified by shiro , shiro that the user's information is stored where were we? How do I get in jsp page ?

Or login authentication , if the login is successful , I have to manually save a current user object in the session ?
------ Solution ---------------------------------------- ----
can do that, the user information stored encrypted in the session
------ Solution --------------------- -----------------------
not used, but nothing more than a few ways to verify the safety , request.getRemoteUser (), request. getUserPrincipal () getName ();.

List <Map <String, int[]>> array adding

 This post last edited by lilewy on 2014-05-25 10:32:26
int [] num1 = {1,2,3,4,5,6};
int [] num2 = {7,8,9,10,11,12};
int [] num3 = {13,14,15,16,17,18};
int [] num4 = {19,20,21,22,23,24};

Map map0 = new HashMap ();
map0.put ("d", num1);
map0.put ("c", num2);
map0.put ("b", num3);
map0.put ("a", num4);
Map map1 = new HashMap ();
map1.put ("d", num1);
map1.put ("c", num2);
map1.put ("b", num3);
map1.put ("a", num4);

List > infoIds = new ArrayList > ();
infoIds.add (map0);
infoIds.add (map1);


think the result is
map0 with the same key adding map1
If the sum is a 38,40,42,44,46,48
b ...., c ...., d ......
return the new Map object
------ Solution ------------------- -------------------------
		int[] num1 = { 1, 2, 3, 4, 5, 6 };
int[] num2 = { 7, 8, 9, 10, 11, 12 };
int[] num3 = { 13, 14, 15, 16, 17, 18 };
int[] num4 = { 19, 20, 21, 22, 23, 24 };

Map<String, int[]> map0 = new HashMap<String, int[]>();
map0.put("d", num1);
map0.put("c", num2);
map0.put("b", num3);
map0.put("a", num4);

Map<String, int[]> map1 = new HashMap<String, int[]>();
map1.put("d", num1);
map1.put("c", num2);
map1.put("b", num3);
map1.put("a", num4);

Map<String, int[]> map2 = new HashMap<String, int[]>();
map2.put("d", num1);
map2.put("c", num2);
map2.put("b", num3);
map2.put("a", num4);

List<Map<String, int[]>> infoIds = new ArrayList<Map<String, int[]>>();
infoIds.add(map0);
infoIds.add(map1);
infoIds.add(map2);

// 需要返回的map对象
Map<String, int[]> newMap = new HashMap<String, int[]>();

Set<String> keys = infoIds.get(0).keySet();
// 遍历map,将其中数组与别一个map相加
for (String key : keys)
{
//新数组
int[] newArr = new int[infoIds.get(0).get(key).length];

//遍历list中的map
for (Map<String, int[]> map : infoIds)
{
int[] array = map.get(key);
for (int i = 0; i < array.length; i++)
{
newArr[i] += array[i];
}
}

newMap.put(key, newArr);
}

System.out.println(newMap.get("a")[0]);

------ For reference only ------- --------------------------------
I'm here with map1 considered map0 the key are the same, and the corresponding key in the array is the same situation
		int[] num1 = { 1, 2, 3, 4, 5, 6 };
int[] num2 = { 7, 8, 9, 10, 11, 12 };
int[] num3 = { 13, 14, 15, 16, 17, 18 };
int[] num4 = { 19, 20, 21, 22, 23, 24 };

Map<String, int[]> map0 = new HashMap<String, int[]>();
map0.put("d", num1);
map0.put("c", num2);
map0.put("b", num3);
map0.put("a", num4);

Map<String, int[]> map1 = new HashMap<String, int[]>();
map1.put("d", num1);
map1.put("c", num2);
map1.put("b", num3);
map1.put("a", num4);

//需要返回的map对象
Map<String, int[]> newMap = new HashMap<String, int[]>();

//遍历map,将其中数组与别一个map相加
Set<String> keys = map0.keySet();
for (String key : keys)
{
int[] array0 = map0.get(key);
int[] array1 = map1.get(key);
int[] newArray = new int[array0.length];
for (int i = 0, len = array0.length; i < len; i++)
{
newArray[i] = array0[i] + array1[i];
}
//将相加后的数组存入新map中
newMap.put(key, newArray);
}

System.out.println(newMap.get("a")[0]);

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


I want to remove the data from the List > infoIds, trouble and then improve the next .
------ For reference only -------------------------------------- -
Map NewMap = new HashMap ();
for (Map maptemp: infoIds) {
Map map = new HashMap ; ( ) ;
for (Map.Entry entry: ; maptemp.entrySet ()) {
String key = entry.getKey ();
int [] value = entry.getValue ( ) ;
if (map.containsKey (key)) {
int [] num = {};
for (int i = 0; i num = new int [value.length];
num [i] = map.get (key) [i] + value [i];
}
map.put (key, num);
} else {
map.put (key, value);
}
}
System.out.println ("----");
System.out.println (" summed up :" + map.get ("a") [0] + "," ; + map.get ("a") [1] + "," + map.get ("a") [2] + "," + map.get ("a") [ 3] + "," + map.get ("a") [4] + "," + map.get ("a") [5]);
NewMap = map;
}
for (int a: NewMap.get ("a")) {
System.out.println (a + ",");
}
leave himself wrote for the collection. Thanks for the reply to the points.

Consult written a sql statement , seeking Great God enlighten. Thank you , Online

now have a table GWSJ_YDLKJH, there is such a place "DD", the value of which he kept a " 432.2-435.6 " " 123.23-343.00 ", "1 #, 2 # ," and other types of characters
only in the above two types of data , there is only one intermediate array " - " and now I want the data in accordance with the " 123.23-343.00 " " 432.2-435.6 ", "1 #, 2 #" this sort of way , that put together the digital type , in accordance with the " - " in front of small to large numbers , followed by a # type into the back , so that how to write a sql statement , seeking great God enlighten. Thank you , Online
------ Solution ------------------------------------ --------

select * from (select * from test_order where dd like '%-%' order by dd) a
union 
select * from (select * from test_order where dd like '%#%' order by dd) b

------ Solution -------------------------- ------------------
What is your database ? sql area to ask it , there more professional
------ Solution ------------------------ --------------------
MySQL can do:
select * from GWSJ_YDLKJH order by instr (DD, '-') = 0, DD;
------ For reference only -------- -------------------------------
on upstairs union should be able to
---- - For reference only ---------------------------------------
2 floor can be
------ For reference only ----------------------------------- ---- wording
each database is not the same , if it is , then the second floor oracle can
------ For reference only ---------------------------------------
thank above . . .

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

this seems not right , oracle database
------ For reference only ------------------ ---------------------
select to_number(substr(dd, 0, instr(t.dd, '-') - 1))as lc
  from GWSJ_YDLKJH t
 order by lc asc


everyone to see me this has not been optimized for
------ For reference only ------------------------- --------------
passing learn
------ For reference only ---------------------------------------
passing learn ! !

java can not generate a result set is empty , scrollable result sets generated problems

public ResultSet executeQuery () throws SQLException {
String sql = "select YHID from YH_INFO where YHID =?";
prepStmt = conn.prepareStatement (sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_UPDATABLE);
prepStmt.setString (1, "zz");
ResultSet rs = prepStmt.executeQuery ();
prepStmt.close ();
return rs;
}
resultset should have results may resultSet is empty


connected oracle 10g, the driver is class12, ojdbc14. scored by the connection pool
------ Solution ------------------- -------------------------
prepStmt.close (); removed.
------ For reference only -------------------------------------- -
break point with it, or the sql statement out, ran into plsql in it, look at the results .
see the value of sql statement not check out , or call the java code problem.

Help cannot be resolved to a variable

 This post last edited by int_java_se on 2014-05-25 18:49:33
public class Encapsulation
{
public int add (int a, int b)
{
return a + b;
}
public int subtract (int a, int b)
{
return a - b;
}
public int multiplication (int a, int b)
{
return a * b;
}
public int division (int a, int b)
{
return a / b;
}
public void sop () / / here is no need to return , the variable name must be familiar with the following variable names are case unity.
{
System.out.println ("hello word");
}
public void returnTest (int x)
{
for (int f = 1; f <10; f + +)
{
if (9 == f)
{
System.out.println (x + "=" + f);
}
}
System.out.println (x);
}
public static void main (String [] args)
{
Encapsulation test = new Encapsulation ();
int a = 8;
int b = 4;
int i = test.add (a, b) ;/ / method calls need to be completed by the object , the method call in the form of : object variable method name ( [ parameter 1 , parameter 2 , parameter 3 .... ) ;
int i1 = test.subtract (a, b);
int i2 = test.multiplication (a, b);
int i3 = test.division (a, b);
System.out.println (i);
System.out.println (i1);
System.out.println (i2);
System.out.println (i3);
test.sop ();
testreturnTest (x); / / error of x cannot be resolved to a variable Editor's Note it

}
}
------ Solution ----------------------------------- ---------
testreturnTest(x); 

What's this ?
1, x is not defined .
2, testreturnTest what stuff .
------ Solution ---------------------------------------- ----
you do not define the variable x course not , public void returnTest previously defined (int x) {} where x is only reurnTest () function in Useful
------ For reference only ------------------------------------- -
X variable , you define where ? ?
------ For reference only -------------------------------------- -
I only declare int is not assigned .
------ For reference only -------------------------------------- -
x?
------ For reference only ---------------------- -----------------
x lie ? landlord or call the compiler about Caesar , x you are passed as arguments , you do not define x, you dare pass ?
------ For reference only ---------------------------------------
; public void returnTest (int x)
{
for (int f = 1; f <10; f + +)
{
if (9 == f)
{
System.out.println (x + "=" + f);
}
}
System.out.println (x);
}
there any way to get X return out , ah, do not define you?
------ For reference only -------------------------------------- -
x this variable is not defined that way

JSP: forward solving





sessionfactory injection error, beg master

Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.hibernate.impl.SessionFactoryImpl' to required type ; 'org.hibernate.SessionFactory' for property 'sessionFactory'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.hibernate.impl . SessionFactoryImpl] to required type [org.hibernate.SessionFactory] for property 'sessionFactory': no ​​matching editors or conversion strategy found
applicationContet.xml

<-! root element of the Spring configuration file , use spring-beans-3.0.xsd semantic constraints - >
xmlns = "http://www.springframework.org/schema/beans"
xsi: schemaLocation = "http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd ">


<-! define a business logic components , to achieve class MyServiceImp ->
class = "org.crazyit.app.service.impl.MyServiceImpl">

<-! defined data source Bean, using C3P0 data source implementation - >
destroy-method = "close">
<-! Specifies the connection to the database driver - >

<-! URL specified connection to the database - >

<-! user name specified connection to the database - >

<-! Specifies the connection to the database password - >

<-! Specifies the connection to the database connection pool maximum number of connections - >

<-! Specifies the connection to the database connection pool minimum number of connections - >

<-! Specifies the connection to the database connection pool initialization connections - >

<-! Specifies the connection to the database connection pool maximum idle time - >


<-! define the Hibernate SessionFactory ->
class = "org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<-! dependency injection data sources , into precisely defined above dataSource ->

<-! mappingResouces attribute is used to list all the mapping file - >


<-! used to list the following Hibernate mapping file - >
org / crazyit / app / domain / Person.hbm.xml


<-! defined Hibernate SessionFactory properties - >

<-! configure Hibernate Properties - >

hibernate.dialect = org.hibernate.dialect.OracleDialect
hibernate.hbm2ddl.auto = update
hibernate.show_sql = true
hibernate.format_sql = true;






<-! definitions DAO Bean ->
class = "org.crazyit.app.dao.impl.PersonDaoHibernate">
<-! inject persistence required to operate SessionFactory ->






Web.xml

xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance"
xsi: schemaLocation = "http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd "version =" 3.0 ">
<-! define the Web application home page - >

index.jsp

<-! location profiles Spring configuration file - >

<-! Use ContextLoaderListener to initialize the Spring container - >

org.springframework.web.context.ContextLoaderListener


<-! define Struts FilterDispathcer of Filter 2 's - >

struts2
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

<-! FilterDispatcher used to initialize Struts 2 and WEB handle all requests . - >

struts2
/ *





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

Spring hibernate can manage , plus they reported the wrong Struts  

session factory using this org.hibernate.impl.SessionFactoryImpl look
------ For reference only ------------------ --------------------- did not see what the problem is on
configuration , ah, why should not you realize SessionFactory SessionFactoryImpl ah ?
------ For reference only -------------------------------------- -
look jar package
you use ------ For reference only --------------------------- ------------
Caused by: org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'org.hibernate. impl.SessionFactoryImpl 'to required type' org.hibernate.SessionFactory 'for property' sessionFactory '; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.hibernate.impl.SessionFactoryImpl] to required type [org.hibernate.SessionFactory] for property 'sessionFactory': no matching editors or conversion strategy found

SessionFactoryImpl can not be converted into org.hibernate.SessionFactory
------ For reference only ------------------- --------------------

antlr-2.7.6.jar, cglib-nodep-2.1_3.jar, com.springsource.org. aopalliance-1.0.0.jar, com.springsource.org.aspectj.weaver-1.6.8.RELEASE.jar, commons-collections-3.1.jar, commons-fileupload-1.2.1.jar, commons-io-1.3. 2.jar, commons-logging-api-1.1.jar, dom4j-1.6.1.jar, ejb3-persistence.jar, freemarker-2.3.16.jar, hibernate3.jar, javassist-3.12.0.GA.jar, jta-1.1.jar, ognl-3.0.jar, ojdbc14.jar, org.springframework.aop-3.0.5.RELEASE.jar, org.springframework.asm-3.0.5.RELEASE.jar, org.springframework.beans- 3.0.5.RELEASE.jar, org.springframework.context-3.0.5.RELEASE.jar, org.springframework.core-3.0.5.RELEASE.jar, org.springframework.expression-3.0.5.RELEASE.jar, org.springframework.jdbc-3.0.5.RELEASE.jar, org.springframework.orm-3.0.5.RELEASE.jar, org.springframework.transaction-3.0.5.RELEASE.jar, org.springframework.web-3.0. 5.RELEASE.jar, servlet-api.jar, slf4j-api-1.6.1.jar, slf4j-nop-1.6.1.jar, struts2-core-2.2.1.jar, struts2-spring-plugin-2.2. 1.jar, xwork-core-2.2.1.jar
------ For reference only ------------------------- --------------

just inherited HibernateDaoSupport, injecting sessionFactory they reported this wrong, very strange, configured to check for a long time did not find how can the problem
------ For reference only --------------------------------------- < br> http://docs.spring.io/spring/docs/2.5.x/api/org/springframework/orm/hibernate3/support/HibernateDaoSupport.html

You can look api declaration must be injected org.hibernate.SessionFactory

------ For reference only ---------------------------------- -----
org.springframework.orm.hibernate3
Class LocalSessionFactoryBean

java.lang.Object
extended by org.springframework.orm.hibernate3.AbstractSessionFactoryBean
extended by org.springframework.orm.hibernate3.LocalSessionFactoryBean
All Implemented Interfaces:
BeanClassLoaderAware, DisposableBean, FactoryBean, InitializingBean, PersistenceExceptionTranslator
Direct Known Subclasses:
AnnotationSessionFactoryBean



little relationship with org.hibernate.SessionFactory destroy both have
------ For reference only ---------------------- -----------------
so either modify the DAO parent , or another sessionfactory
------ For reference only --- ------------------------------------

Spring can manage hibernate , plus Struts they reported on the wrong
------ For reference only ------------------------------- What --------
final solution is ? brother have encountered such a problem. Solving .