struts 相关问题

Apache Struts Web框架是一个免费的开源解决方案,用于创建Java Web应用程序。

Java MVC Struts 响应原始字符串

我有一个用 Struts (MVC) 制作的 Java 项目,我需要将响应作为原始字符串发送 struts.xml: 我有一个用 Struts (MVC) 制作的 Java 项目,我需要将响应作为原始字符串发送 struts.xml: <struts> <constant name="struts.devMode" value="true"></constant> <constant name="struts.ui.theme" value="simple"></constant> <constant name="struts.xwork.chaining.copyErrors" value="true"></constant> <constant name="struts.xwork.chainingcopyMessages" value="true"></constant> <package name="basicstruts6" extends="struts-default" namespace="/"> <default-action-ref name="init"></default-action-ref> <action name="init" class="some.class.path.mvc.ServiceTestAction" method="init"> <result name="success">/WEB-INF/app/index.jsp</result> </action> <action name="invokeService" class="some.class.path.mvc.ServiceTestAction" method="execute"> <result name="success">/WEB-INF/app/index.jsp</result> </action> </package> </struts> 在 <action name="invokeService" class="some.class.path.mvc.ServiceTestAction" method="execute"> 中,我想用我定义的原始字符串进行响应,而不使用 index.jsp 文件作为模型。 我仍然想要 some.class.path.mvc.ServiceTestAction 处理请求,但想直接写入响应编写器 同时我想设置响应的HTTP代码。如果出现错误,我想使用 HTTP 400 进行响应并将正文直接写入响应编写器。 如果您不想返回index.jsp作为结果,那么您应该在struts.xml中删除此代码 <result name="success">/WEB-INF/app/index.jsp</result> </ 在操作类 execute() 方法中 return SUCCESS 放置 return NONE。 如果您的操作类实现了 HttpServletRequest 和 HttpServletResponse,您可以获得 ServletRequestAware 和 ServletResponseAware。 您还可以阅读这个答案:How to get the request body and response body in apache struts2? - 使用 $.ajax. 发布 在操作 execute() 方法中,您使用 servlet API 向响应写入一些文本。类似的东西 PrintWriter writer = httpServletResponse.getWriter(); writer.println("hello server"); writer.flush(); httpServletResponse.setStatus(400);

回答 1 投票 0

Struts 2 选择带有数组列表值的标签

我正在开发一个简单的struts应用程序。在我的 JSP 中,我有一个下拉列表框(使用 s:select 标签)。我需要用操作类中的数组列表值填充这些值。我怎样才能做到这一点?什么

回答 2 投票 0

Struts 上的 Rest API

我目前正在为struts应用程序添加rest服务。我们使用的struts是1.x。我发现rest插件仅支持struts2,而且该插件也不是完全restful...

回答 2 投票 0

Struts - Struts 提供的 JSP 页面中 .tld 的 Taglib 指令

我正在开发一个基于Struts 的应用程序。我是 Struts 新手。我想在 JSP 页面中使用在 Struts 提供的 taglib 目录中指定的 html 标签。 但不知道如何使用它。我知道嗬...

回答 3 投票 0

从 Struts 2.3.37 迁移到 2.5.33

https://cwiki.apache.org/confluence/display/WW/Struts+2.3+to+2.5+migration 我已经按照上面的页面从struts 2.3迁移到struts 2.5。我有 更改了与struts men相关的包名称...

回答 1 投票 0

java.lang.NoSuchMethodError:org.apache.tiles.impl.BasicTilesContainer.setApplicationContext(Lorg/apache/tiles/request/ApplicationContext;)V

从 Struts 2.3.37 迁移到 Struts 2.5.33。 我已经参考了下面给出的页面 https://cwiki.apache.org/confluence/display/WW/Struts+2.3+to+2.5+migration 我在运行时遇到错误...

回答 1 投票 0

从 struts 2.3.37 迁移到 struts 2.5.33

我已参考以下页面 https://cwiki.apache.org/confluence/display/WW/Struts+2.3+to+2.5+migration 我在 tomcat (v9.0.45) 上运行时遇到错误 严重:发送异常

回答 1 投票 0

Struts 2 MVC 架构中的混乱

我正在研究Struts2的Action,了解到Struts 2中的Controller是FilterDispatcher,Model是Action。 但之前我知道 Action 和 FilterDispatcher 都是 Controller...

回答 2 投票 0

注册操作返回请求的资源不可用

我有一个包含以下代码的表单: 请报名 <... 我有一个包含以下代码的表单: <form action="doRegister" class="form-signup" > <h2 class="form-signup-heading">Please sign up</h2> <input type="email" class="form-control" placeholder="Email address" required autofocus> <input type="password" class="form-control" placeholder="Password" required> <input type="password" class="form-control" placeholder="Password control" required> <input type="text" class="form-control" placeholder="Name" required> <input type="text" class="form-control" placeholder="Surname" required> <input type="date" class="form-control" placeholder="Born date" required> <button class="btn btn-lg btn-primary btn-block" type="submit">Sign up</button> </form 我有两个班级:UserRegisterForm和UserRegistrationAction UserRegisterForm: package com.github.jcpp.jathenaeum.action; import org.apache.struts.action.ActionForm; public class UserRegisterForm extends ActionForm{ private static final long serialVersionUID = 1; /*ATTRIBUTES of the form fields*/ /*METHODS Get and Set*/ public UserRegisterForm() { super(); } } UserRegistrationAction: package com.github.jcpp.jathenaeum.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.github.jcpp.jathenaeum.Utente; import com.github.jcpp.jathenaeum.db.dao.UtenteDAO; import com.github.jcpp.jathenaeum.exceptions.RegistrationException; public class UserRegistrationAction extends Action{ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //boolean action_perform = false; String action_target = null; Random rnd = new Random(); UtenteDAO userDao = new UtenteDAO(); Utente user = new Utente(); //ActionMessages errors_mesg = new ActionMessages(); UserRegisterForm uf = (UserRegisterForm) form; if(form != null){ user.setEmail(uf.getEmail()); user.setPassword(uf.getPassword()); user.setNome(uf.getName()); user.setCognome(uf.getSurname()); user.setDataNascita(uf.getBornDate()); user.setNumeroTessera(rnd.nextInt(999999)+1); try{ if(userDao.register(user)){ action_target = "success"; } }catch(Exception e){ action_target = "failed"; throw new RegistrationException(); } } return mapping.findForward(action_target); } 在我的struts-config.xml中我: <form-beans> <form-bean name="registerform" type="com.github.jcpp.jathenaeum.action.UserRegisterForm"/> </form-beans> <action-mappings> <action path="/index" type="org.apache.struts.actions.ForwardAction" parameter="page.index" /> <action path="/signin" type="org.apache.struts.actions.ForwardAction" parameter="page.signin" /> <action path="/signup" type="org.apache.struts.actions.ForwardAction" parameter="page.signup" /> <action path="/doRegister" type="com.github.jcpp.jathenaeum.action.UserRegistrationAction" name="registerform" scope="request" validate="true" input="signup"> <forward name="input" path="/index.jsp"/> <forward name="success" path="/welcome.jsp"/> <forward name="failure" path="/index.jsp"/> </action> </action-mappings> 我的错误报告是: 类型状态报告 留言 /JAthenaeum/doRegister 描述 请求的资源不可用。 为什么我会遇到这个问题? 问题在于表单中的 action 参数:在我的例子中它必须是 doRegister.do,而在 struts-config.xml 中,操作路径等于 /doRegister。所以,请看下面的代码: <form action="doRegister.do" > [...] </form> 并且在 struts-config.xml <action path="/doRegister" <!-- LOOK HERE --> type="com.github.jcpp.jathenaeum.action.UserRegistrationAction" name="registerform" scope="request" validate="true" input="/signup.jsp"> <!-- <forward name="input" path="/index.jsp"/> <forward name="success" path="/signin.jsp"/> <forward name="failed" path="/signup.jsp"/> --> </action> 该操作返回名为 "failed" 的未知转发。将其更改为配置为操作 "failure" 的值。应替换以下代码 try { if(!userDao.register(user)) { return mapping.findForward("failure"); } }catch(Exception e){ throw new RegistrationException(e); } return mapping.findForward("success"); 异常应该提供更多信息,告诉您异常的原因。 表格也应该映射到正确的操作 <html:form action="/doRegister" cssClass="form-signup" >

回答 2 投票 0

注册操作返回请求的资源不可用

我有一个包含以下代码的表单: 请报名 <... 我有一个包含以下代码的表单: <form action="doRegister" class="form-signup" > <h2 class="form-signup-heading">Please sign up</h2> <input type="email" class="form-control" placeholder="Email address" required autofocus> <input type="password" class="form-control" placeholder="Password" required> <input type="password" class="form-control" placeholder="Password control" required> <input type="text" class="form-control" placeholder="Name" required> <input type="text" class="form-control" placeholder="Surname" required> <input type="date" class="form-control" placeholder="Born date" required> <button class="btn btn-lg btn-primary btn-block" type="submit">Sign up</button> </form 我有两个班级:UserRegisterForm和UserRegistrationAction UserRegisterForm: package com.github.jcpp.jathenaeum.action; import org.apache.struts.action.ActionForm; public class UserRegisterForm extends ActionForm{ private static final long serialVersionUID = 1; /*ATTRIBUTES of the form fields*/ /*METHODS Get and Set*/ public UserRegisterForm() { super(); } } UserRegistrationAction: package com.github.jcpp.jathenaeum.action; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.struts.action.Action; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionForward; import org.apache.struts.action.ActionMapping; import com.github.jcpp.jathenaeum.Utente; import com.github.jcpp.jathenaeum.db.dao.UtenteDAO; import com.github.jcpp.jathenaeum.exceptions.RegistrationException; public class UserRegistrationAction extends Action{ @Override public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { //boolean action_perform = false; String action_target = null; Random rnd = new Random(); UtenteDAO userDao = new UtenteDAO(); Utente user = new Utente(); //ActionMessages errors_mesg = new ActionMessages(); UserRegisterForm uf = (UserRegisterForm) form; if(form != null){ user.setEmail(uf.getEmail()); user.setPassword(uf.getPassword()); user.setNome(uf.getName()); user.setCognome(uf.getSurname()); user.setDataNascita(uf.getBornDate()); user.setNumeroTessera(rnd.nextInt(999999)+1); try{ if(userDao.register(user)){ action_target = "success"; } }catch(Exception e){ action_target = "failed"; throw new RegistrationException(); } } return mapping.findForward(action_target); } 在我的struts-config.xml中我: <form-beans> <form-bean name="registerform" type="com.github.jcpp.jathenaeum.action.UserRegisterForm"/> </form-beans> <action-mappings> <action path="/index" type="org.apache.struts.actions.ForwardAction" parameter="page.index" /> <action path="/signin" type="org.apache.struts.actions.ForwardAction" parameter="page.signin" /> <action path="/signup" type="org.apache.struts.actions.ForwardAction" parameter="page.signup" /> <action path="/doRegister" type="com.github.jcpp.jathenaeum.action.UserRegistrationAction" name="registerform" scope="request" validate="true" input="signup"> <forward name="input" path="/index.jsp"/> <forward name="success" path="/welcome.jsp"/> <forward name="failure" path="/index.jsp"/> </action> </action-mappings> 我的错误报告是: 类型状态报告 留言 /JAthenaeum/doRegister 描述 请求的资源不可用。 为什么我会遇到这个问题? 问题在于表单中的 action 参数:在我的例子中它必须是 doRegister.do,而在 struts-config.xml 中,操作路径等于 /doRegister。所以,请看下面的代码: <form action="doRegister.do" > [...] </form> 并且在 struts-config.xml <action path="/doRegister" <!-- LOOK HERE --> type="com.github.jcpp.jathenaeum.action.UserRegistrationAction" name="registerform" scope="request" validate="true" input="/signup.jsp"> <!-- <forward name="input" path="/index.jsp"/> <forward name="success" path="/signin.jsp"/> <forward name="failed" path="/signup.jsp"/> --> </action> 该操作返回名为 "failed" 的未知转发。将其更改为配置为操作 "failure" 的值。应替换以下代码 try { if(!userDao.register(user)) { return mapping.findForward("failure"); } }catch(Exception e){ throw new RegistrationException(e); } return mapping.findForward("success"); 异常应该提供更多信息,告诉您异常的原因。 表格也应该映射到正确的操作 <html:form action="/doRegister" cssClass="form-signup" >

回答 2 投票 0

使用struts刷新页面的一部分而不使用ajax

各位,在struts中是否可以不使用ajax来刷新页面的一部分。请告诉我。

回答 1 投票 0

如何通过自定义Struts类型转换器转换列表项的字段?

我需要在 Company 和 Employee 类中实现 ID 字段的自定义转换。我已经实现了从 StrutsTypeConverter 扩展的自定义转换器,并成功用于转换

回答 2 投票 0

地址已被使用:JVM_Bind java

有时每当我重新启动应用程序时,该应用程序是基于 爪哇 支柱 Mysql和Jboss 4.05版本 我收到错误地址已在使用中:JVM_Bind 我知道的唯一修复方法是重新启动

回答 10 投票 0

为什么浏览器显示空白网页?

我的欢迎页面是 web.xml 文件中列出的welcome.jsp welcome.jsp 包含一个简单的表单,用于提交到由 struts-config.xml 文件映射的操作 所有映射都是正确的...

回答 1 投票 0

我正在创建一个 Struts-tiles 项目,具有以下基本细节

(1)我的欢迎页面是web.xml文件中列出的welcome.jsp (2)welcome.jsp 包含一个简单的表单,用于提交到由 struts-config.xml 文件映射的操作 (3)所有映射都是正确的...

回答 2 投票 0

Struts 逻辑:迭代

我正在使用struts逻辑:迭代,我需要更改它写出的最后一行的样式。 我在 iterate 标签上有一个 bean:size 和 indexId,但我无法找出逻辑组合......

回答 2 投票 0

org.apache.struts.action 不存在

下面我给出了我的代码,它显示了一些错误,它说 org.apache.struts.action 不存在,我能做什么,请告诉我解决方案...... 导入 javax.servlet.http.HttpSession; 导入...

回答 2 投票 0

如何知道从哪个类收到请求

我的应用程序中有一个login.jsp 页面。我使用 Struts 2 和一个简单的 validate() 方法来验证我的表单。我有两个问题: 我的表单 bean 类中的 validate() 方法验证表单。 ...

回答 3 投票 0

在 spring-struts Web 应用程序中,DTO 对象如何从客户端传输到服务器而不实现可序列化

我有一个使用 Spring - Struts 框架开发的 Web 应用程序,部署在 Tomcat 8 服务器中。该应用程序仅托管在一台服务器上。 应用程序代码分层如下 行动|业务流程外包 | ...

回答 1 投票 0

如何在Struts2中提交表单的URL中传递参数

我正在Struts2中做一个项目,我需要在URL中设置一个参数,就像下面链接中的用户参数一样。 我希望当我单击表单提交按钮而不是任何链接时传递此参数

回答 2 投票 0

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.