我在做例子时总是说这行有错误<c:out value="${error}"></c:out>
错误如下:
org.apache.jasper.JasperException: /WEB-INF/fail.jsp(29,2) According to TLD or attribute directive in tag file, attribute value does not accept any expressions
org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:357)
org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:141)
org.apache.jasper.compiler.Validator$ValidateVisitor.checkXmlAttributes(Validator.java:940)
org.apache.jasper.compiler.Validator$ValidateVisitor.visit(Validator.java:695)
org.apache.jasper.compiler.Node$CustomTag.accept(Node.java:1441)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Validator.validate(Validator.java:1474)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:214)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:439)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:422)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:507)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:274)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.springframework.web.servlet.view.InternalResourceView.renderMergedOutputModel(InternalResourceView.java:111)
org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:250)
org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:965)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:744)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:663)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:394)
org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:358)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
jsp页面代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%> <%@ taglib prefix="c" uri="/WEB-INF/c.tld" %> <%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %> <% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>ok</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <c:out value="${error}"></c:out><br> </body> </html>
1 楼
lsy
2007-04-09
web.xml
加上下面的代码没有啊?
加上下面的代码没有啊?
<taglib> <taglib-uri>/WEB-INF/core.tld</taglib-uri> <taglib-location>/WEB-INF/tld/c.tld</taglib-location> </taglib>
2 楼
jamesby
2007-04-09
http://jamesby.iteye.com/admin/show/53055
3 楼
genius0182
2007-04-09
我加了。
web.xml如下:
web.xml如下:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> <servlet> <servlet-name>web</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>2</load-on-startup> </servlet> <servlet-mapping> <servlet-name>web</servlet-name> <url-pattern>*.htm</url-pattern> </servlet-mapping> <servlet> <servlet-name>context</servlet-name> <servlet-class>org.springframework.web.context.ContextLoaderServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <welcome-file-list> <welcome-file> login.jsp </welcome-file> </welcome-file-list> <taglib> <taglib-uri>/spring</taglib-uri> <taglib-location>/WEB-INF/spring.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/c.tld</taglib-uri> <taglib-location>/WEB-INF/c.tld</taglib-location> </taglib> <taglib> <taglib-uri>/WEB-INF/fmt.tld</taglib-uri> <taglib-location>/WEB-INF/fmt.tld</taglib-location> </taglib> </web-app>
4 楼
rainlife
2007-04-09
引用
# <%@ taglib prefix="c" uri="/WEB-INF/c.tld" %>
# <%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
# <%@ taglib prefix="fmt" uri="/WEB-INF/fmt.tld" %>
这个用法是对的,在容器启动的时候,会自动地将JSTL支持加载进来的,而并不用在web.xml中做什么配置。不知道你的包有没有导入正确,另外,你是不是试一下用<c:set />将error设置一下?
5 楼
genius0182
2007-04-09
包我导进去了。 我的error在Contrller中设了。我用
这么用就好使。一换成表达式的形式就出上面的错误。
String error = (String)request.getAttribute("error"); <%=error%>
这么用就好使。一换成表达式的形式就出上面的错误。
6 楼
genius0182
2007-04-09
这是我的处理器。
/** * */ package web; import java.util.HashMap; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.SimpleFormController; import org.springframework.web.servlet.view.RedirectView; import pojo.Tusers; import service.UserService; /** * @author Administrator * */ public class FormController extends SimpleFormController { private UserService userservice; private String fail_view; private String success_view; protected ModelAndView onSubmit(Object command) throws Exception{ Tusers tt = (Tusers)command; System.out.println("userName: "+tt.getUserName()); System.out.println("password: "+tt.getPassword()); HashMap hm = new HashMap(); try { userservice.checkLogin(tt); hm.put("userName", tt.getUserName()); } catch(RuntimeException e) { hm.put("error", e.getMessage()); System.out.println(e); // return new ModelAndView(new RedirectView(this.getFail_view()),hm); return new ModelAndView(this.getFail_view(),hm); } return new ModelAndView(this.getSuccess_view(),hm); } /** * @return the userservice */ public UserService getUserservice() { return userservice; } /** * @param userservice the userservice to set */ public void setUserservice(UserService userservice) { this.userservice = userservice; } /** * @return the fail_view */ public String getFail_view() { return fail_view; } /** * @param fail_view the fail_view to set */ public void setFail_view(String fail_view) { this.fail_view = fail_view; } /** * @return the success_view */ public String getSuccess_view() { return success_view; } /** * @param success_view the success_view to set */ public void setSuccess_view(String success_view) { this.success_view = success_view; } }
7 楼
rainlife
2007-04-09
哦,你用的是Spring啊,使用JSTL的话,要让Spring支持JSTL才行的,必须使用一个特殊的JstView类,在执行JSTL前完成一些初始化的工作。
8 楼
genius0182
2007-04-09
你说的初始化工作是不是配置文件里的东西呀?
配置文件如下:
请看看有什么地方不正确吗?
配置文件如下:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd"> <beans> <bean id="FormController" class="web.FormController"> <property name="sessionForm"><value>true</value></property> <property name="commandName"><value>user</value></property> <property name="commandClass"><value>pojo.Tusers</value></property> <property name="formView"><value>login</value></property> <property name="fail_view"> <value>fail</value> </property> <property name="success_view"> <value>ok</value> </property> <property name="userservice"> <ref bean="userService" /> </property> </bean> <bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping"> <property name="mappings"> <props> <prop key="/login.htm">FormController</prop> </props> </property> </bean> <bean id="viewResolver" class = "org.springframework.web.servlet.view.InternalResourceViewResolver"> <property name="viewClass"><value>org.springframework.web.servlet.view.JstlView</value></property> <property name ="prefix"><value>/WEB-INF/</value></property> <property name ="suffix"><value>.jsp</value></property> </bean> </beans>
请看看有什么地方不正确吗?
9 楼
hgq0011
2007-04-10
“attribute value does not accept any expressions “不能接收表达示。那你就研究一下jstl<c:out>到底怎么写撒。
10 楼
genius0182
2007-04-11
问题解决了,我把JSTL1.1的包导进去就好用了。应该是以前的c标签太老的原因。谢谢大家的参与。