index.jsp
Html代码
- <body>
- <a href="login2.do">登陆(struts标签)</a><br>
- </body>
struts-config.xml
Xml代码
- <action path="/login2"
- forward="/login_use_struts_tag.jsp"
- ></action>
- <action path="/loginusetag"
- type="com.tangjian.action.LoginAction"
- name="loginForm"
- >
- <forward name="success" path="/login_success.jsp"/>
- <forward name="error" path="/login_use_struts_tag.jsp"/>
- </action>
login_use_struts_tag.jsp
Html代码
- <body>
- <h1>用户登陆-使用struts标签保持数据</h1>
- <hr>
- <form action="loginusetag.do" method="post">
- 用户名:<html:text property="username"/><br>
- 密 码:<html:password property="password" value=""/><br>
- <input type="submit" value="提交">
- </form>
- </body>
运行之后,报了如下错误:
Java代码
- 严重: Servlet.service() for servlet jsp threw exception
- javax.servlet.jsp.JspException: Cannot find bean: "org.apache.struts.taglib.html.BEAN" in any scope
- at org.apache.struts.taglib.TagUtils.lookup(TagUtils.java:935)
- at org.apache.struts.taglib.html.BaseFieldTag.prepareValue(BaseFieldTag.java:121)
- at org.apache.struts.taglib.html.BaseFieldTag.renderInputElement(BaseFieldTag.java:102)
- at org.apache.struts.taglib.html.BaseFieldTag.doStartTag(BaseFieldTag.java:81)
- at org.apache.jsp.login_005fuse_005fstruts_005ftag_jsp._jspx_meth_html_005ftext_005f0(login_005fuse_005fstruts_005ftag_jsp.java:100)
- at org.apache.jsp.login_005fuse_005fstruts_005ftag_jsp._jspService(login_005fuse_005fstruts_005ftag_jsp.java:68)
- at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
- at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
- at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
- at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
- at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:679)
- at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:461)
- at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:399)
- at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:301)
- at org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1085)
- at org.apache.struts.action.RequestProcessor.internalModuleRelativeForward(RequestProcessor.java:1023)
- at org.apache.struts.action.RequestProcessor.processForward(RequestProcessor.java:572)
- at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:221)
- at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
- at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:414)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:627)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
- at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
- at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
- at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
- at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:172)
- at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
- at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
- at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
- at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:174)
- at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:873)
- at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
- at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
- at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
- at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
- at java.lang.Thread.run(Thread.java:619)
- 2010-1-11 0:17:22 org.apache.catalina.core.StandardWrapperValve invoke
一开始报错后,总感觉没错。
到最后把使用的标签全部换成struts的运行了下才好了。也就是把form标签也改成struts的标签。
更改的login_use_struts_tag.jsp
Html代码
- <body>
- <h1>用户登陆-使用struts标签保持数据</h1>
- <hr>
- <html:form action="loginusetag.do" method="post">
- 用户名:<html:text property="username"/><br>
- 密 码:<html:password property="password" value=""/><br>
- <input type="submit" value="提交">
- </html:form>
- </body>
为什么html标签和struts的标签不能混用的原因没有去深究,只是给自己提个醒:以后页面尽量不要使用不同风格的标签,这样感觉应该不会错吧!
原文出自:http://tj-dragon.iteye.com/blog/567159
时间: 2024-10-14 08:55:23