Struts2标签与jsp页面Java代码的值相互使用

版权声明:本文为博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/ning_vina/article/details/84731573

业务需求:

Struts标签使用Jsp页面中的list的值,java代码使用Struts传来的值

 

	<s:iterator value="secondTypes1"  status="s1">
	   <li><a href=<%=basePath+"indexGoods/showSecondType?goodsSecondTypeId=" %>
                <s:property value="goodsSecondTypeId"/> class="underline">
                 <s:property value="goodsSecondName"/></a>
		<!-- 显示三级列表 -->
		<% 
		  ValueStack vs = (ValueStack)request.getAttribute("struts.valueStack");
                  Integer secondTypeIdtoThird = (Integer)vs.findValue("goodsSecondTypeId");
                  IGoodsTypeDAO goodsTypeDAO = DaoFactory.getGoodsTypeDAO();
                  out.print(secondTypeIdtoThird);
                  List<GoodsType> goodsTypes = 
                goodsTypeDAO.getGoodsThirdTypesBySecond(secondTypeIdtoThird).getGoodsTypes();
		  request.setAttribute("goodsTypes", goodsTypes);
                                                 %>		       
		  <s:iterator  value="#request.goodsTypes">
				  <s:property  value="goodsTypeName"/>
			</s:iterator>					       
			 </li>
					</s:iterator>

 

 

展开阅读全文

JSP页面调用struts2标签遇到问题

04-17

在MyEclipse8.5中开发的rnJSP页面代码:<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>rn<%@ taglib prefix="s" uri="/struts-tags"%>rn<%@ taglib prefix="html" uri="/META-INF/tlds/struts-html.tld"%> rnrn如果没有rn<%@ taglib prefix="html" uri="/META-INF/tlds/struts-html.tld"%>rn就不报错。rn错误提示:rn2011-4-17 1:31:33 org.apache.catalina.core.ApplicationDispatcher invokern严重: Servlet.service() for servlet jsp threw exceptionrnjava.lang.ClassNotFoundException: org.apache.struts.taglib.html.MessagesTeirn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1358)rn at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1204)rn at org.apache.jasper.compiler.TagLibraryInfoImpl.createTagInfo(TagLibraryInfoImpl.java:416)rn at org.apache.jasper.compiler.TagLibraryInfoImpl.parseTLD(TagLibraryInfoImpl.java:250)rn at org.apache.jasper.compiler.TagLibraryInfoImpl.(TagLibraryInfoImpl.java:163)rn at org.apache.jasper.compiler.Parser.parseTaglibDirective(Parser.java:420)rn at org.apache.jasper.compiler.Parser.parseDirective(Parser.java:476)rn at org.apache.jasper.compiler.Parser.parseElements(Parser.java:1426)rn at org.apache.jasper.compiler.Parser.parse(Parser.java:133)rn at org.apache.jasper.compiler.ParserController.doParse(ParserController.java:216)rn at org.apache.jasper.compiler.ParserController.parse(ParserController.java:103)rn at org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:167)rn at org.apache.jasper.compiler.Compiler.compile(Compiler.java:306)rn at org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)rn at org.apache.jasper.compiler.Compiler.compile(Compiler.java:273)rn at org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:566)rn at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:317)rn at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)rn at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:654)rn at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:445)rn at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:379)rn at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:292)rn at org.apache.struts2.dispatcher.ServletDispatcherResult.doExecute(ServletDispatcherResult.java:154)rn at org.apache.struts2.dispatcher.StrutsResultSupport.execute(StrutsResultSupport.java:186)rn at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:362)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:266)rn at com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:165)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:252)rn at org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ConversionErrorInterceptor.intercept(ConversionErrorInterceptor.java:122)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ParametersInterceptor.doIntercept(ParametersInterceptor.java:195)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.StaticParametersInterceptor.intercept(StaticParametersInterceptor.java:179)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.MultiselectInterceptor.intercept(MultiselectInterceptor.java:75)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.CheckboxInterceptor.intercept(CheckboxInterceptor.java:94)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:235)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ModelDrivenInterceptor.intercept(ModelDrivenInterceptor.java:89)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ScopedModelDrivenInterceptor.intercept(ScopedModelDrivenInterceptor.java:130)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:267)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ChainingInterceptor.intercept(ChainingInterceptor.java:126)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.PrepareInterceptor.doIntercept(PrepareInterceptor.java:138)rn at com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:165)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.interceptor.ServletConfigInterceptor.intercept(ServletConfigInterceptor.java:164)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.AliasInterceptor.intercept(AliasInterceptor.java:179)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at com.opensymphony.xwork2.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:176)rn at com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:237)rn at org.apache.struts2.impl.StrutsActionProxy.execute(StrutsActionProxy.java:52)rn at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:488)rn at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77)rn at org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter(StrutsPrepareAndExecuteFilter.java:91)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)rn at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)rn at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)rn at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)rn at java.lang.Thread.run(Thread.java:619) 论坛

jsp页面使用struts2标签后出现500错误

06-24

//index.jsprnrn<%@ page language="java" pageEncoding="utf-8"%>rn<%@ taglib prefix="s" uri="/struts-tags"%>rnrnrnrn rn rn My JSP 'index.jsp' starting pagern rn rn rn rn rn rn 姓名: rn rn 密码rn rn rn rn rn rn rn rnrn该页面使用了struts2标签,当在网页中输入http://localhost:8080/test/index.jsp,当页面加载时,出现了错误rntype Exception reportrnrnmessage rnrndescription The server encountered an internal error () that prevented it from fulfilling this request.rnrnexception rnrnorg.apache.jasper.JasperException: Exception in JSP: /index.jsp:13rnrn10: rn11: rn12: rn13: rn14: rn15: 濮撳悕锛� rn16: rnrnrnStacktrace:rn org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rnrnrnroot cause rnrnjava.lang.NullPointerExceptionrn org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:58)rn org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:54)rn org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:49)rn org.apache.jsp.index_jsp._jspx_meth_s_005fform_005f0(index_jsp.java:98)rn org.apache.jsp.index_jsp._jspService(index_jsp.java:71)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:803)rnrnrnnote The full stack trace of the root cause is available in the Apache Tomcat/5.5.25 logs.rnrn问这是怎么回事,怎么解决吗? 论坛

前台jsp页面使用Struts2标签就报错

03-14

web.xml代码rn[code=html]rnrnrn a01rn rn index.jsprn rn rn rn struts2rn org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterrn rn rn struts2rn /*rn rnrn[/code]rnrn前台index.jsprn[code=html]rn<%@ page language="java" contentType="text/html; charset=ISO-8859-1"rn pageEncoding="ISO-8859-1"%>rn<%@ taglib uri="/struts-tags" prefix="s" %>rnrnrnrn rn Insert title herernrnrnrnrnrn[/code]rnrn上面的页面上访问就报错:rnHTTP Status 500 - An exception occurred processing JSP page /index.jsp at line 11rnrn--------------------------------------------------------------------------------rnrntype Exception reportrnrnmessage An exception occurred processing JSP page /index.jsp at line 11rnrndescription The server encountered an internal error that prevented it from fulfilling this request.rnrnexception rnorg.apache.jasper.JasperException: An exception occurred processing JSP page /index.jsp at line 11rnrn8: Insert title herern9: rn10: rn11: rn12: rn13: rnrnStacktrace:rn org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:521)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:430)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn root cause rnThe Struts dispatcher cannot be found. This is usually caused by using Struts tags without the associated filter. Struts tags are only usable when the request has passed through its servlet filter, which initializes the Struts dispatcher needed for this tag. - [unknown location]rn org.apache.struts2.views.jsp.TagUtils.getStack(TagUtils.java:60)rn org.apache.struts2.views.jsp.StrutsBodyTagSupport.getStack(StrutsBodyTagSupport.java:44)rn org.apache.struts2.views.jsp.ComponentTagSupport.doStartTag(ComponentTagSupport.java:48)rn org.apache.jsp.index_jsp._jspx_meth_s_005fform_005f0(index_jsp.java:97)rn org.apache.jsp.index_jsp._jspService(index_jsp.java:66)rn org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rn org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388)rn org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)rn org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)rn javax.servlet.http.HttpServlet.service(HttpServlet.java:717)rnrn note The full stack trace of the root cause is available in the Apache Tomcat/6.0.36 logs.rn--------------------------------------------------------------------------------rnApache Tomcat/6.0.36rnrn只要把index.jsp中的“<%@ taglib uri="/struts-tags" prefix="s" %>”和“”去掉就能运行。 论坛

struts2标签jsp页面取不到值,新手求学,老手赐教

11-06

问题情况:设置struts框架后,建立index.jsp页面,HelloWorldAction.java,MessageStore.java,rn我想通过index页面请求action获取MessageStore.java中的message的值然后输出到HelloWorld页面,但是后value没获取值。rn全部代码和主要设置如下:rnindex .jsprn<%@page import="com.opensymphony.xwork2.util.*" %>rn<%@ taglib prefix="s" uri="/struts-tags" %>rn<%@ page language="java" contentType="text/html; charset=ISO-8859-1"rn pageEncoding="ISO-8859-1"%>rnrnrnrnrn rn Basic Struts 2 Application - Welcomernrnrn Welcome To Struts 2!rn Hello WorldrnrnrnrnrnrnHelloWorld.jsp:rnrn<%@page import="com.opensymphony.xwork2.util.*" %>rn<%@ taglib prefix="s" uri="/struts-tags" %>rnrn<%@ page language="java" contentType="text/html; charset=ISO-8859-1"rn pageEncoding="ISO-8859-1"%>rnrnrnrnrn rn Hello World!rnrnrn [color=#FF0000][/color]rn <%%>rnrnrnrnrnrnMessageStore.java:rnrnrnpackage hellomodel;rnrnpublic class MessageStore rn private String message;rn public MessageStore()rn setMessage("Hello,Struts user!");rn rn public void setMessage(String message)rn this.message=message;rn rn public String getMesssage()rn return message;rn rnrnrnrnrnHelloWorldAction.java:rnrnrnpackage helloaction;rnimport hellomodel.MessageStore;rnimport com.opensymphony.xwork2.ActionSupport;rnrnpublic class HelloWorldAction extends ActionSupport rnrn /**rn * rn */rn private static final long serialVersionUID = 1L;rn private MessageStore messageStore;rn public String excute() throws Exceptionrn messageStore=new MessageStore();rn //this.setMessageStore(msg);rn return SUCCESS;rn rn public MessageStore getMessageStore() rn return messageStore;rn rnrn public void setMessageStore(MessageStore messageStore) rn this.messageStore = messageStore;rn rnrnrnrnstruts.config:rnrnrnrnrnrnrn rnrn rn rn rn /index.jsprn rnrn/HelloWorld.jsprnrn rnrnrnrnweb.xmlrnrnrnrn Basic_Struts2_Antrn rn index.jsprn rn rn struts2rn org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilterrnrnrn struts2rn /*rnrnrnrnrnrn其中红色部分是我想获得字符串“Hello,Struts user!"的地方,但是只显示默认的no value,鼓捣3天了,请给个明白的解释吧,谢谢 论坛

没有更多推荐了,返回首页