在托管bean的方法里用了session.setAttribute,程序就出错.......

pcenshao 2010-06-02
这是托管bean的代码
package pcenshao.pet_store.mbean;

import java.util.Map;

import javax.faces.context.FacesContext;

import pcenshao.pet_store.Grobal;
import pcenshao.pet_store.SpringUtil;
import pcenshao.pet_store.entity.Adopter;
import pcenshao.pet_store.service.AdopterService;
import pcenshao.pet_store.vo.AdopterVO;

public class AdopterLogin {
	private Adopter ad;
	private AdopterService as;
	private String msg;
	
	public AdopterLogin(){
		this.ad = new Adopter();
		this.as = (AdopterService)SpringUtil
					.getApplicationContext()
					.getBean("adopterService");		
	}
	
	
	public String login(){
		if(this.as.login(ad)){
			Map<String,Object> s=
					FacesContext.getCurrentInstance()
								.getExternalContext()
								.getSessionMap();
			
			s.put(Grobal.Type, Grobal.TypeAdopter);
			s.put(Grobal.User, ad);
			
			return "success";
		}
		this.setMsg("用户名或密码错误");
		return "";
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getMsg() {
		return msg;
	}


	public void setAd(Adopter ad) {
		this.ad = ad;
	}


	public Adopter getAd() {
		return ad;
	}
	
}


下面是faces-config.xml
<?xml version='1.0' encoding='UTF-8'?>

<faces-config xmlns="http://java.sun.com/xml/ns/javaee"
	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-facesconfig_1_2.xsd"
	version="1.2">
	<!--
		<lifecycle> <phase-listener> </phase-listener> </lifecycle>
	-->
	<managed-bean>
		<managed-bean-name>al</managed-bean-name>
		<managed-bean-class>pcenshao.pet_store.mbean.AdminLogin</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	<managed-bean>
		<managed-bean-name>ah</managed-bean-name>
		<managed-bean-class>pcenshao.pet_store.mbean.AdminHome</managed-bean-class>
		<managed-bean-scope>session</managed-bean-scope>
	</managed-bean>
	<managed-bean>
		<managed-bean-name>h</managed-bean-name>
		<managed-bean-class>pcenshao.pet_store.mbean.Home</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	<managed-bean>
		<managed-bean-name>r</managed-bean-name>
		<managed-bean-class>pcenshao.pet_store.mbean.Reg</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>
	<managed-bean>
		<managed-bean-name>l</managed-bean-name>
		<managed-bean-class>pcenshao.pet_store.mbean.AdopterLogin</managed-bean-class>
		<managed-bean-scope>request</managed-bean-scope>
	</managed-bean>

	<navigation-rule>
		<from-view-id>/admin/al.jsp</from-view-id>
		<navigation-case>
			<from-outcome>adminHome</from-outcome>
			<to-view-id>/admin/ah.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>
	<navigation-rule>
		<from-view-id>/login.jsp</from-view-id>
		<navigation-case>
			<from-outcome>success</from-outcome>
			<to-view-id>/h.jsp</to-view-id>
		</navigation-case>
	</navigation-rule>

</faces-config>


下面是错误信息
javax.servlet.ServletException: Not a Valid Method Expression:
javax.faces.webapp.FacesServlet.service(FacesServlet.java:256)

root cause

javax.el.ELException: Not a Valid Method Expression:
org.apache.el.lang.ExpressionBuilder.createMethodExpression(ExpressionBuilder.java:209)
org.apache.el.ExpressionFactoryImpl.createMethodExpression(ExpressionFactoryImpl.java:57)
org.apache.jsp.h_jsp._jspx_meth_h_005fcommandButton_005f0(h_jsp.java:954)
org.apache.jsp.h_jsp._jspx_meth_h_005fcolumn_005f4(h_jsp.java:865)
org.apache.jsp.h_jsp._jspx_meth_c_005fif_005f1(h_jsp.java:824)
org.apache.jsp.h_jsp._jspx_meth_h_005fdataTable_005f0(h_jsp.java:291)
org.apache.jsp.h_jsp._jspx_meth_h_005fform_005f0(h_jsp.java:229)
org.apache.jsp.h_jsp._jspx_meth_f_005fview_005f0(h_jsp.java:157)
org.apache.jsp.h_jsp._jspService(h_jsp.java:114)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
com.sun.faces.context.ExternalContextImpl.dispatch(ExternalContextImpl.java:428)
com.sun.faces.application.ViewHandlerImpl.executePageToBuildView(ViewHandlerImpl.java:444)
com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:116)
com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:106)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:251)
com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:144)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:245)







我实在是搞不明白了
如果我把AdopterLogin类里的login方法里的s.put(Grobal.User, ad);去掉
就没有错
为什么呀??真是郁闷
terryzhou 2010-06-02
JSP呢?页面报错,你咋光贴BEAN
pcenshao 2010-06-03
terryzhou 写道
JSP呢?页面报错,你咋光贴BEAN

以下便是jsp文件关键部分

	<f:view>
	<center>
		<h:form>
			<h:outputText value="#{login.msg}" style="color:red"></h:outputText>
			<h:panelGrid columns="2">
				<f:facet name="header">
					<h:outputText value="领养者登录"></h:outputText>
				</f:facet>
				<h:outputText value="用户名:"  ></h:outputText>
				<h:inputText value="#{login.ad.name}" id="name" required="true"></h:inputText>
				<h:outputText value="密  码:"></h:outputText>
				<h:inputSecret value="#{login.ad.password}" id="password" required="true" ></h:inputSecret>
			</h:panelGrid>	
			<h:panelGroup >
				<h:commandButton value="登录" action="#{login.login}"></h:commandButton>
			</h:panelGroup>		
			<h:panelGroup>
				<h:message for="name"></h:message>
				<h:message for="password"></h:message>
			</h:panelGroup>
		</h:form>
	</center>
	</f:view>
terryzhou 2010-06-03
是不是h.jsp?
最好 全部 贴上来

s.put(Grobal.User, ad); 
换成
s.put(Grobal.User, null); 

报错么?
pcenshao 2010-06-03
terryzhou 写道
是不是h.jsp?
最好 全部 贴上来

s.put(Grobal.User, ad); 
换成
s.put(Grobal.User, null); 

报错么?



不报
terryzhou 2010-06-03
<navigation-rule> 
        <from-view-id>/login.jsp</from-view-id> 
        <navigation-case> 
            <from-outcome>success</from-outcome> 
            <to-view-id>/h.jsp</to-view-id> 
        </navigation-case> 
    </navigation-rule> 
are you sure?
你帖的是login.jsp?
报错的是h.jsp
pcenshao 2010-06-03
terryzhou 写道
<navigation-rule> 
        <from-view-id>/login.jsp</from-view-id> 
        <navigation-case> 
            <from-outcome>success</from-outcome> 
            <to-view-id>/h.jsp</to-view-id> 
        </navigation-case> 
    </navigation-rule> 
are you sure?
你帖的是login.jsp?
报错的是h.jsp



我是后来改成login.jsp的
貌似我试的时候跟这没关系
terryzhou 2010-06-04
异常信息显示的BUTTON里的ACTION或ACTIONLISTENER表达式不合法(方法不存在)。
和你描述的问题不同。
应该是LOGIN.JSP-->LOGIN.LOGIN-->用户登录成功-->H.JSP(报错)。

你如果改了啥,就把改之后的两个页面,一个BEAN,faces-config贴上来
pcenshao 2010-06-04
terryzhou 写道
异常信息显示的BUTTON里的ACTION或ACTIONLISTENER表达式不合法(方法不存在)。
和你描述的问题不同。
应该是LOGIN.JSP-->LOGIN.LOGIN-->用户登录成功-->H.JSP(报错)。

你如果改了啥,就把改之后的两个页面,一个BEAN,faces-config贴上来



bean是一样的 只是faces-config.xml里配置的bean名字不一样

不过bean名字跟jsp上的bean名字是对应的
terryzhou 2010-06-04
org.apache.jsp.h_jsp._jspx_meth_h_005fcommandButton_005f0(h_jsp.java:954) 
org.apache.jsp.h_jsp._jspx_meth_h_005fcolumn_005f4(h_jsp.java:865) 
org.apache.jsp.h_jsp._jspx_meth_c_005fif_005f1(h_jsp.java:824) 
org.apache.jsp.h_jsp._jspx_meth_h_005fdataTable_005f0(h_jsp.java:291) 
org.apache.jsp.h_jsp._jspx_meth_h_005fform_005f0(h_jsp.java:229) 
org.apache.jsp.h_jsp._jspx_meth_f_005fview_005f0(h_jsp.java:157) 
org.apache.jsp.h_jsp._jspService(h_jsp.java:114) 

 <navigation-case>  
            <from-outcome>success</from-outcome>  
            <to-view-id>/h.jsp</to-view-id>  
        </navigation-case> 

之前就说了,是h.jsp里报的错,和你帖的这页面没关系,跟你改不改BEAN名字更没关系
Global site tag (gtag.js) - Google Analytics