我正在做餐馆送货上门的网站,取决于餐厅的送货时间我需要启用/禁用立即订购按钮
我有12小时格式的startTime和End Time.
这是代码
var startTime = '8:30 AM' ;
var endTime = '6:30 PM' ;
var formatTime = (function () {
function addZero(num) {
return (num >= 0 && num < 10) ? "0" + num : num + "";
}
return function (dt) {
var formatted = '';
if (dt) {
var hours24 = dt.getHours();
var hours = ((hours24 + 11) % 12) + 1;
formatted = [formatted, [addZero(hours), addZero(dt.getMinutes())].join(":"),hours24>11?"pm" :"am"].join(" ");
}
return formatted;
}
})();
var …Run Code Online (Sandbox Code Playgroud) 我以这种格式记录了一个日期
2014-12-09 02:18:38
Run Code Online (Sandbox Code Playgroud)
我需要将其转换为
09-12-2014 02:18:38
Run Code Online (Sandbox Code Playgroud)
我尝试过这种方式转换
import java.text.ParseException;
import java.text.SimpleDateFormat;
public class TestDate {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sdf = new SimpleDateFormat("dd-mm-YYYY HH:mm:ss");
String input = "2014-12-09 02:18:38";
String strDate = sdf.format(input);
System.out.println(strDate);
}
}
Run Code Online (Sandbox Code Playgroud)
但是我在运行时遇到了这个异常
Exception in thread "main" java.lang.IllegalArgumentException: Cannot format given Object as a Date
at java.text.DateFormat.format(DateFormat.java:301)
at java.text.Format.format(Format.java:157)
at TestDate.main(TestDate.java:15)
Run Code Online (Sandbox Code Playgroud)
有人可以帮我解决这个问题.
我在Struts2中看到了拦截器的概念.我在Struts2的教程中看到了下面的例子.
在此示例中,作者使用拦截器通过访问HttpSession和检查凭据来检查凭据USER_KEY.
访问HttpSession拦截器本身是一个坏主意吗?我猜拦截器是Java EE编程中的简单servlet过滤器.
我觉得访问的最佳位置HttpSession是Struts2中的action类.
如果我错了,请纠正我.
public class AuthorizationInterceptor extends AbstractInterceptor {
private static final String USER_KEY = "user";
public String intercept(ActionInvocation invocation) throws Exception {
Map session = invocation.getInvocationContext().getSession();
if (session.get(USER_KEY) == null) {
addActionError(invocation, "You must be authenticated to access this page");
return Action.ERROR;
}
return invocation.invoke();
}
private void addActionError(ActionInvocation invocation, String message) {
Object action = invocation.getAction();
if (action instanceof ValidationAware) {
((ValidationAware) action).addActionError(message);
}
}
}
Run Code Online (Sandbox Code Playgroud) 我已将现有的Maven项目导入Eclipse IDE.我修改了一些代码并在Eclipse中构建了项目.没有构建错误.
但是,当我mvn clean install从命令提示符运行时,它显示了很多编译错误.为什么Eclipse没有显示错误,而Maven显示编译错误?
这是我的第一个Portlet.我没有在servlet中获取值.请看节目.在我的自定义portlet Java类doView()方法中,我展示了一个JSP页面
public void doView(RenderRequest renderRequest, RenderResponse renderResponse)
throws IOException, PortletException {
include(viewJSP, renderRequest, renderResponse);
}
Run Code Online (Sandbox Code Playgroud)
在view.jsp页面内部,我引用一个servlet来接收值:
<form action="formServlet" method="post">
<h1>Please Login</h1>
Login: <input type="text" name="login"><br>
Password: <input type="password" name="password"><br>
<input type=submit value="Login">
</form>
Run Code Online (Sandbox Code Playgroud)
内部web.xml文件:
<servlet>
<servlet-name>formServlet</servlet-name>
<servlet-class>FormServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>formServlet</servlet-name>
<url-pattern>formServlet</url-pattern>
</servlet-mapping>
Run Code Online (Sandbox Code Playgroud)
在我的servlet里面
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name = (String)request.getParameter("login");
System.out.println("The Name is "+name);
}
Run Code Online (Sandbox Code Playgroud)
但我不知道为什么没有调用servlet.
我正在使用Liferay 6进行开发,我开发了Liferay6 Struts2 Portlet并进行了部署.使用Custom JSPs Hooks,我已经覆盖$ PORTAL_ROOT_HOME/html/portlet/login login.jsp并创建了我自己的jsp页面,如图所示
<HTML>
<HEAD>
<TITLE>Login using jsp</TITLE>
</HEAD>
<BODY>
<H1>LOGIN FORM</H1>
<form>
<table>
<tr>
<td> Username : </td><td> <input name="username" size=15 type="text" /> </td>
</tr>
<tr>
<td> Password : </td><td> <input name="password" size=15 type="text" /> </td>
</tr>
</table>
<input type="submit" value="login" />
</form>
</BODY>
</HTML>
Run Code Online (Sandbox Code Playgroud)
这很好用,自定义jsp页面正在显示.现在请点击提交按钮告诉我,如何判断验证凭证aganist数据库的java类.
请告诉我如何在课堂上接受这些价值并验证它们.
谢谢
我在HashMap中存储了一个double值,如图所示
HashMap listMap = new HashMap();
double mvalue =0.0;
listMap.put("mvalue",mvalue );
Run Code Online (Sandbox Code Playgroud)
现在,当我试图检索该值时,如图所示
mvalue = Double.parseDouble((String) listMap.get("mvalue"));
Run Code Online (Sandbox Code Playgroud)
我收到一个错误
java.lang.Double无法强制转换为java.lang.String
我在这里很困惑,
这是我的实际HashMap,我正在设置它中的值,如图所示
HashMap listMap = new HashMap();
double mvalue =0.0 ;
List<Bag> bagList = null;
listMap.put("bagItems",bagList);
listMap.put("mvalue", mvalue);
Run Code Online (Sandbox Code Playgroud)
有人可以告诉我,HashMap的结构应该如何?
我编写了我的应用程序,我遇到了一个要求,我需要将String转换为char数组I.
String str_a = "Testing";
char c[] = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
Run Code Online (Sandbox Code Playgroud)
因为我没有初始化 char c[]
我的问题是为什么它不抛出NullPointerException,通常这应该这样做
char[] char_array = new char[str_a.length()];
char_array = str_a.toCharArray();
for (char d : c) {
System.out.println(d);
}
Run Code Online (Sandbox Code Playgroud) 我的目录中有一个名为"Parser"的文件夹.
我正在尝试将此文件夹(Parser)从我自己的目录复制到/ home/vinay下的同事目录
但我得到了这个例外
cp:无法创建目录`/ home/vinay/Parser':权限被拒绝
这些是我执行的命令.
-bash-3.00$ cp -r Parser /home/vinay/
cp: cannot create directory `/home/vinay/Parser': Permission denied
Run Code Online (Sandbox Code Playgroud) 我正在为我的应用程序使用Hibernate 3版本.
在浏览Hibernate的教程时,我发现SessionFactory应该只为应用程序创建一次.所以为此,我决定在类中使用静态块,并使用静态方法返回如图所示.
public class SessionFactoryInitiliaztion {
static {
try {
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Exception x) {
x.printStackTrace();
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Run Code Online (Sandbox Code Playgroud)
我究竟需要在哪里关闭这个sessionFactory对象,以便它重新调用内存?