为什么这不起作用:
download.html
<a href="jsplogin.jar">download</a>
Run Code Online (Sandbox Code Playgroud)
jsplogin.jar文件在同一个文件夹中有download.html文件
就在昨天它起作用了
当我点击下载链接时,文件jsplogin.jar应该下载,但它试图在浏览器中打开该文件.当我右键单击链接并选择"保存链接"时,没有任何事情发生
这是login.jsp中代码的一部分
login.jsp的
<h2 class="swd-postheader">Login</h2>
<form method="post" action="Login.select">
<p><input id="username" name= "username" type="text" placeholder="Username" style="margin:10px" autofocus required></p>
<p> <input id="password" name="password" type="password" placeholder="Password" style="margin:10px" required></p>
<p><input class="swd-button" type="submit" value="Sign In">
<a href="register.html"><button class="swd-button" type="button">New User</button></a>
</p>
</form>
<h2><%=request.getAttribute("errorMessage") %></h2>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
在servlet代码中,如果用户不存在,我正在使用带有错误消息的requestdispatcher
的servlet
if(res.next())
{
if ((thisname.equals(res.getString("username"))) && (thispwd.equals(res.getString("password"))))
{
session.setAttribute("username", request.getParameter("username"));
response.sendRedirect("login-success.html");
}
else{
session.invalidate();
request.setAttribute("errorMessage", "Invalid user or password");
RequestDispatcher rd = request.getRequestDispatcher("/login.jsp");
rd.forward(request, response);
}
Run Code Online (Sandbox Code Playgroud)
但是<h2><%=request.getAttribute("errorMessage") %></h2>只要登录jsp打开就会运行,当没有失败时会在页面上返回null.只有当失败时它会显示"无效的用户或密码".所以我想检查request.getAttribute("errorMessage")是否是空值 .是不是然后调用<h2><%=request.getAttribute("errorMessage") %></h2>.我该怎么做?或者,还有更好的方法
在这里,当我运行下面的代码时,我得到called输出,我想知道为什么不called new.因为1来自两个short和int范围.
public class MyClass {
private int x;
public MyClass(){
this(1);
}
public MyClass(int x){
System.out.println("called");
this.x = x;
}
public MyClass(short y){
System.out.println("called new");
this.x = y;
}
public static void main(String args[]) {
MyClass m = new MyClass();
System.out.println("hello");
}
}
Run Code Online (Sandbox Code Playgroud)