jsp 相关问题

JSP(JavaServer Pages)是一种在服务器上运行的基于Java的视图技术,它允许您在(客户端语言,如HTML,CSS,JavaScript等)中编写模板文本,并与后端Java代码进行交互。

从操作类将数据发送到另一个 JSP 文件

主页有创建新记录的链接和显示所有现有记录的链接。 在 create_new_record 页面上,我正在将所有数据写入名为 saveRecords 的操作类方法中的文件...

回答 1 投票 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

提交表单到Servlet后如何在JSP中保留HTML表单字段值?

提交 HTML 中的数据后,servlet 将这些数据添加到我的数据库中,并将结果消息转发到 JSP 页面。我想在转发后保留表单中最初提交的值...

回答 2 投票 0

从JSP连接MySQL

我刚刚踏上JSP。我开始编写简单的程序来显示日期、系统信息。然后我尝试连接 MySQL 数据库我有一个免费的托管帐户,但我无法连接到 MySQL

回答 4 投票 0

如何将struts2中的字符集更改为utf-8

嗨,我有一个测试字段,我想在其中进行非英语测试(例如俄语) 但在我的动作课中,我得到的不仅仅是文本?????????。 我尝试编写简单的过滤器来描述

回答 4 投票 0

找不到文件

我的计划是检查所有文本字段是否为空。如果为空,我想显示错误消息并继续显示 SignUp.jsp。这是代码: if (uEmail.isEmpty() || uFName.is...

回答 1 投票 0

如何在按钮单击时在请求参数中传递 html 输入值

我有一个使用表内核心库动态生成的书籍列表。用户可以选择要添加到购物车的书籍数量,然后单击“添加到购物车”按钮。我想要的是...

回答 1 投票 0

在jsp中找不到合适的驱动程序,但不作为java应用程序

所以我正在启动一个Web应用程序,我想使用JSP页面(我以前使用过它们)来动态访问数据库并从不同的表中检索数据。 我现在已经有了一个基本的数据库...

回答 2 投票 0

为jsp页面分配IP地址

我只是想知道是否真的可以将IP地址分配给我在eclipse中开发的jsp页面。 我的要求是我希望这个 JSP 页面在我的电脑的 IP 地址上使用特定的

jsp
回答 1 投票 0

Wildfly Jakarta EE 10 多部分表格缺失

在从 Wildfly 25 升级到 Wildfly 27(及更高版本)的过程中,我们不再看到多部分表单。 请求部分为空(见下文底部)。所以,我不确定它在哪里......

回答 1 投票 0

为什么我不能在我的jsp中使用核心标签库?

当我在 jsp 中包含 taglib 时遇到了麻烦。当我启动 tomcat 时,出现以下错误报告。 使它从工作到不工作的特定线路是这样的 <%@ ...

回答 1 投票 0

数据库更新问题

我有一个使用java,jsp,servlet实现的Web应用程序。每当我在数据库表中有更新时,我的 DAO 中的数组列表就应该更新。有没有更好的解决方案。 索尔...

回答 2 投票 0

如何解决这个问题 服务器不支持 3.0 版的 J2EE Web 模块规范。?

我正在尝试在tomcat5.5中部署jsp-servlet应用程序,但当我尝试部署到服务器时显示此错误。 服务器不支持 3.0 版本的 J2EE Web 模块规范...

回答 3 投票 0

定义自定义 JSP 标签

我正在尝试创建一个使用其他自定义标记的自定义 JSP 标记。 我的方法是这样的: 公共 int doAfterBody() 抛出 JspTagException { BodyContent bc = getBodyContent(); if (bc != nu...

回答 2 投票 0

创建自定义 JSP 标签

在我的JSP中有代码: "/> 我想用这样的东西替换它: 在我的JSP中有代码: <img src="<c:out value="${requestScope['img_url']}"/>"/> 我想用这样的东西替换它: <xyz:img src="${requestScope['img_url']}"/> 我尝试了Struts Taglib,但它需要Struts。还有其他选择吗? 这只是自定义 JSP 标签。有一个很棒的 Sun/Oracle 教程 以及许多其他很棒的资源。 编辑:原始链接不再有效,我不知道替换网址。此存档链接应包含与原始帖子发布时相同的内容。 这篇文章帮助我找到了一个非常简单的解决方案:使用标签文件封装可重用内容 创建文件WEB-INF/tags/img.tag 将此标头添加到 JSP:<%@taglib tagdir="/WEB-INF/tags" prefix="xyz" %> 就用它吧:)

回答 2 投票 0

如何在自定义JSP错误页面中查看并显示异常信息和状态码?

我知道我可以像这样在 web.xml 中添加一些内容 java.lang.Throwable /错误.jsp 我知道我可以像这样在 web.xml 中添加一些内容 <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/error.jsp</location> </error-page> 然而,jsp 页面不会显示任何建设性信息,因为它无法获取异常到底是什么。我知道我们可以通过各种 exception-type 将不同的异常转发到不同的页面,但是在 web.xml 中编写的内容太多了。我希望一页就足够了,另一页可以处理 404 之类的错误。 那么应该如何将异常信息传递到jsp页面呢?使用会话? 理想的情况可能是页面获取异常信息并显示一些相关消息,而不向用户透露异常。相反,它可以将其记录到文件中以供将来参考。实现这一目标的最佳方法是什么?谢谢。 有关异常的信息已经可通过多个请求属性获得。您可以在 the RequestDispatcher javadoc: 中找到所有这些属性的名称 ERROR_EXCEPTION - javax.servlet.error.exeption ERROR_EXCEPTION_TYPE - javax.servlet.error.exception_type ERROR_MESSAGE - javax.servlet.error.message ERROR_REQUEST_URI - javax.servlet.error.request_uri ERROR_SERVLET_NAME - javax.servlet.error.servlet_name ERROR_STATUS_CODE - javax.servlet.error.status_code 所以,简而言之,这个 JSP 示例应该显示所有可能的异常详细信息: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> ... <ul> <li>Exception: <c:out value="${requestScope['javax.servlet.error.exception']}" /></li> <li>Exception type: <c:out value="${requestScope['javax.servlet.error.exception_type']}" /></li> <li>Exception message: <c:out value="${requestScope['javax.servlet.error.message']}" /></li> <li>Request URI: <c:out value="${requestScope['javax.servlet.error.request_uri']}" /></li> <li>Servlet name: <c:out value="${requestScope['javax.servlet.error.servlet_name']}" /></li> <li>Status code: <c:out value="${requestScope['javax.servlet.error.status_code']}" /></li> </ul> 此外,您还可以展示这些有用的信息: <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> <%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %> <jsp:useBean id="date" class="java.util.Date" /> ... <ul> <li>Timestamp: <fmt:formatDate value="${date}" type="both" dateStyle="long" timeStyle="long" /></li> <li>User agent: <c:out value="${header['user-agent']}" /></li> </ul> 当您将页面标记为错误页面时,具体的 Exception 实例本身在 JSP 中仅可用作 ${exception}: <%@ page isErrorPage="true" %> ... ${exception} 仅当您使用 EL 2.2 或更高版本时,您才可以打印其堆栈跟踪,如下所示: <%@ page isErrorPage="true" %> ... <pre>${pageContext.out.flush()}${exception.printStackTrace(pageContext.response.writer)}</pre> 或者,如果您尚未使用 EL 2.2,则为此创建一个 自定义 EL 函数: public final class Functions { private Functions() {} public static String printStackTrace(Throwable exception) { StringWriter stringWriter = new StringWriter(); exception.printStackTrace(new PrintWriter(stringWriter, true)); return stringWriter.toString(); } } 注册于/WEB-INF/functions.tld: <?xml version="1.0" encoding="UTF-8" ?> <taglib xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd" version="2.1"> <display-name>Custom Functions</display-name> <tlib-version>1.0</tlib-version> <uri>http://example.com/functions</uri> <function> <name>printStackTrace</name> <function-class>com.example.Functions</function-class> <function-signature>java.lang.String printStackTrace(java.lang.Throwable)</function-signature> </function> </taglib> 并且可以用作 <%@ taglib prefix="my" uri="http://example.com/functions" %> ... <pre>${my:printStackTrace(exception)}</pre> 对于异常的日志记录,最简单的地方是filter,它映射到/*的URL模式上,并且基本上执行以下操作: try { chain.doFilter(request, response); } catch (ServletException e) { log(e.getRootCause()); throw e; } catch (IOException e) { // If necessary? Usually not thrown by business code. log(e); throw e; } 是的,在我看来,会话是存储与当前请求相关的异常的好地方。 处理完异常后不要忘记清除它。 此外,您还可以将错误代码从支持代码传递到表示层,而不是异常,在表示层中可以使用属性文件将其转换为某种对用户而言意味着完全错误的代码。

回答 2 投票 0

使用100vh时溢出

我将网格视图高度设置为 100vh。我的网格视图由两个 div 组成,第一个 div 用于图像,第二个 div 用于表单。这是我的 CSS 代码的一部分: * { 框大小:边框框; } html{ 字体-...

回答 1 投票 0

WSO2:有没有办法在源代码中自定义开发门户和发布者?

我下载了 WSO2 API Manager 源代码,我想自定义它具有的一些 .jsx 文件。但没有任何 .jsx 文件。 我知道有一种方法可以自定义devportal并发布...

回答 2 投票 0

jsp:include 的正确语法是什么?

我的应用程序是 Servlet 和 Spring 的混合体。 大多数页面都分为几个小节,使用 jsp:include 包含在主 jsp 中。 当导入目标是 REST 时,我遇到一些问题...

回答 1 投票 0

© www.soinside.com 2019 - 2024. All rights reserved.