我正在尝试用JSP实现将当前月份添加一个月的功能,并用html在教科书中显示结果

我正在尝试用JSP实现将当前月份添加一个月的功能,并用html在教科书中显示结果,html,jsp,intellij-idea,Html,Jsp,Intellij Idea,这是我的输入框,应该显示一个月内的日期 <div class="form-group"> <label for="datum_uplate">Datum isteka:</label> <input type="date" class="form-control" id="datum_isteka" name="datum_isteka" > 由于您没有添加jsp页面的完整代码,根据日志堆栈跟踪,我认为原因是:

这是我的输入框,应该显示一个月内的日期

      <div class="form-group">
      <label for="datum_uplate">Datum isteka:</label>
      <input type="date" class="form-control" id="datum_isteka" name="datum_isteka" >

由于您没有添加jsp页面的完整代码,根据日志堆栈跟踪,我认为原因是:

您已经使用了LocalDateTime,但没有导入它,因为它的包是java.time,并且没有在jsp中导入默认值


要解决此问题,只需在jsp页面的顶部添加以下内容即可

,因为下面的一行出现了错误:

int months = int.Parse("datum_isteka".toString());
您正在使用的语法在Java中不起作用

如果我的想法是正确的,那么您正在尝试获取输入值并希望在jsp中进行求值,这是不可能的,因为jsp代码将在您可以在浏览器中看到html内容之前执行

如果您不想在代码中使用JavaScript,那么要获得文本框值,您需要提交如下页面:

<!-- here I am using post method, coz I dont want users to see the content in the browser -->
<form method="post" action="index.jsp">

  <div class="form-group">
  <label for="datum_uplate">Datum isteka:</label>
  <input type="date" class="form-control" id="datum_isteka" name="datum_isteka" >        

  <input type="submit" value="Get Months">
</form>

 <%
  // to get the you use the java code
  if (request.getParameter("datum_isteka") != null ) {
     LocalDateTime.now().plusMonths(1);
     //int months = int.Parse("datum_isteka".toString());
     int months = Integer.parseInt(request.getParameter("datum_isteka")); // here you may need to handle empty string, `parseInt` method will throw error if the given value is empty, i.e; `datum_isteka` textbox value.
     LocalDateTime newDate = LocalDateTime.now().plusMonths(months);
  }
%>

现在,newDate将具有所需的值。

在tomcat中部署应用程序时,您能在控制台或日志文件中看到任何其他错误吗?我能看到的唯一其他错误是带有解析类的jsp代码谢谢您的回答,但它不起作用。。我尝试了所有可能的功能aahSo我应该将什么类型的数据放入数据库以便插入?将iznos、datum_uplate、datum_isteka、id_clan、tip_clan_id、id_naloga值'24'、'2018-05-07',5、2插入到uplate中,从clanovi中选择id_naloga,其中id_clan=5;:数据截断:不正确的日期值:对于第1行org.apache.jasper.servlet.JspServletWrapper.handleJspExceptionJspServletWrapper.java:601的“datum_isteka”列,用户是否可以看到结果并不重要。它也可以是javascript,我只想让它自动工作
int months = int.Parse("datum_isteka".toString());
<!-- here I am using post method, coz I dont want users to see the content in the browser -->
<form method="post" action="index.jsp">

  <div class="form-group">
  <label for="datum_uplate">Datum isteka:</label>
  <input type="date" class="form-control" id="datum_isteka" name="datum_isteka" >        

  <input type="submit" value="Get Months">
</form>

 <%
  // to get the you use the java code
  if (request.getParameter("datum_isteka") != null ) {
     LocalDateTime.now().plusMonths(1);
     //int months = int.Parse("datum_isteka".toString());
     int months = Integer.parseInt(request.getParameter("datum_isteka")); // here you may need to handle empty string, `parseInt` method will throw error if the given value is empty, i.e; `datum_isteka` textbox value.
     LocalDateTime newDate = LocalDateTime.now().plusMonths(months);
  }
%>