Tag: actionresult

Struts 2动作方法和struts.convention.result.path不起作用

我有Struts2动作方法和struts.convention.result.path这是我的struts.xml login.jsp 当我运行url “localhost:8080/venus/user/login” 。 它显示错误”HTTP Status 404 – /venus/user/login.jsp” 如果我将login()方法更改为execute()方法,它可以工作。 或者如果我改为/WEB-INF/pages/login.jsp ,它就可以了。 任何人都可以解释和教我如何在xml中使用动作方法与结果路径配置? 非常感谢你!

Struts 2当用户插入不存在的动作时该怎么做

在Struts 2应用程序中,当用户插入与您的任何操作无关的URL时,会出现java.lang.NullPointerException 在这些情况下,我想显示一个漂亮的屏幕,所以我已经添加到我的struts.xml /WEB-INF/jsp/exception.jsp 但它不起作用。 我也尝试过没有成功 /WEB-INF/jsp/exception.jsp 所以,我开始认为所有的URL都必须与一个动作对应,否则当用户插入与任何动作不对应的URL时,没有机制来处理这些情况(所以这个机制是处理由NullpointerException引起的您现有的一个动作,而不是一个不存在的动作。

如何在不使用任何操作类的情况下使用Struts2约定

在Struts2中,我们可以在不使用struts.xml动作类的情况下定义动作,如下所示: /error.jsp 在我的应用程序中,我使用struts2 convention 。 在这种情况下如何避免编写动作类。 我有很多场景,我只想在不使用任何业务逻辑的情况下访问该页面。 我的结果路径不仅仅是一个JSP。 我正在使用瓷砖。 我使用的代码如下: @Action(value=”homePage”, results={@Result(name=”success”, location=”homePage”, type=”tiles”)})

使用Struts 2输出时出现JSONexception错误

当我将结果执行到浏览器中时,我收到JSONexception错误,如下所示: type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.hibernate.LazyInitializationException: failed to lazily initialize a collection of role: com.ProductDetails.ISN, no session or session was closed org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:209) org.apache.struts2.json.JSONWriter.process(JSONWriter.java:140) org.apache.struts2.json.JSONWriter.value(JSONWriter.java:216) org.apache.struts2.json.JSONWriter.write(JSONWriter.java:94) org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:115) org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:200) org.apache.struts2.json.JSONResult.execute(JSONResult.java:172) com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:361) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:265) com.opensymphony.xwork2.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:163) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) com.opensymphony.xwork2.DefaultActionInvocation.invoke(DefaultActionInvocation.java:236) com.opensymphony.xwork2.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:249) org.apache.struts2.interceptor.validation.AnnotationValidationInterceptor.doIntercept(AnnotationValidationInterceptor.java:68) com.opensymphony.xwork2.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:87) […]

在struts 2中的同一个动作方法中使用多个结果类型?

我在我的action方法中使用了结果类型流,这取决于ajax调用。 这个ajax调用是在我的JSP上的文本字段焦点上激活的。 此AJAX调用的function是,如果用户输入的数据已存在于后端服务器中,则显示错误。 基本上,服务器返回一个状态代码,指定业务逻辑的结果,即在我的情况下,如果我的服务器返回1016,数据已经存在于服务器中,因此我显示错误。 但是,我还必须在我的action类方法中为代码实现exception处理。 在这种情况下,实际发生的事情是我想要转发焦点的页面在我的错误应该显示的位置混乱,我的网页上输出非常难看。 我尝试了所有我可以重定向到另一个页面,但似乎没有任何工作,我得到的只是2页混乱到一个。 这是我的particluar方法的struts.xml代码(如前所述): text/html inputStream 这是AJAX方法: request = $.ajax({ url: “ao/useridCheck.action”, method: “POST”, data: { customerLoginId : userid }, dataType: “text” }); request.done(function( response ) { if(response!=””) { $(‘.error-customerId’).html(”+response+”); $(‘.error-customerId’).prev().addClass(‘error-field’); v = 1; } else { $(‘.error-customerId’).text(”); $(‘.error-customerId’).prev().removeClass(‘error-field’); } //$(‘#customerLoginId’).addClass(‘error-field’); // $(‘.error-amount’).prev().addClass(‘error-field’); }); request.fail(function( jqXHR, textStatus ) { alert( “Request […]

在Struts 2中从Java获取JSON对象

我试图使用getJSON jQuery方法从java服务器获取响应文本。 虽然,当java类是简单格式( String , List和Map )时,我可以得到响应数据,但是在使用其他java对象时我无法获得成功数据。 以下Java类是简单类型并获取访问成功数据和工作 package com.awitd.framework.action; import com.opensymphony.xwork2.Action; public class getAllJson implements Action{ private String data; public String getData() { return data; } public void setData(String data) { this.data = data; } public String execute() { System.out.println(” this is from action”); data = “[“; data += “{“; data += “\”objid\”:\”” + […]

没有为动作和结果输入定义结果

这是我的struts.xml 当我调用loadcity.action我收到以下错误 No result defined for action roseindia.action.user.RegisterUser and result input 这是我的行动方法: public String loadcity() { country=request.getParameter(“country”); cityList= dao.loadcity(country); return ActionSupport.SUCCESS; }

关于Struts2中的Action Mapping – 没有映射Action

我正在尝试运行我的struts应用程序,但我得到一个错误操作未映射我已经看到它是正确的命名空间但仍然得到错误? struts.xml : 我的register.xml : /register.jsp register.jsp 我正在validation我的注册页面和validationXML如下 RegisterAction-validation.xml: 6 true 而我的register.jsp如下: Validation Struts page 我的项目结构如下: Strutsvalidation –src–> com.struts2(package)–> register.xml, registeraction-validation.xml, javaclasses, struts.xml –webcontent–> web-inf–> web.xml register.jsp(in web content) 我得到的错误如下? There is no Action mapped for action name Register. – [unknown location] at com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185) at org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63) at org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37) at com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58) at org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:552) at org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:77) at […]

没有为行动和结果定义结果

默认结果不是仅使用我的包的结果进行渲染。 Flow转到我的n0result方法然后它抛出Exception 。 请更正我错误的配置。 输出: Hello How are you noresult() method got called….. Dec 26, 2013 12:48:04 PM org.apache.struts2.dispatcher.Dispatcher serviceAction SEVERE: Could not find action or result No result defined for action leo.struts.HelloWorldAction and result noresult – action – file:/D:/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/Strut2Examples/WEB-INF/classes/struts.xml:99:93 at com.opensymphony.xwork2.DefaultActionInvocation.executeResult(DefaultActionInvocation.java:350) 形成: 在struts.xml /noresultend.jsp /noresultdefaultdispatcher.jsp 行动: public String noresult() throws Exception { System.out.println(“Hello How […]

Struts2 URL无法访问

我真的很喜欢Struts2 – 我可以通过省略部分路径来访问JSP页面。 注意路径假设包含pages/welcome_user.jsp 。 关键是要查看路径中的单词pages 。 这是struts.xml文件: pages/login.jsp pages/welcome_user.jsp 我可以通过以下方式访问login.jsp : http://localhost/Struts2Example/User/Login 和welcome_user.jsp通过: http://localhost/Struts2Example/User/Welcome 请注意,在这两个URL中,我都可以删除pages ,为什么? 来源: http : //www.mkyong.com/misc/how-to-use-mkyong-tutorial/ 有人可以通过上面的教程告诉我有什么问题吗?