Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/84.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 是否有更好的方法使用<;将值从jsp传递到servlet;a href>;_Java_Html_Jsp_Servlets - Fatal编程技术网

Java 是否有更好的方法使用<;将值从jsp传递到servlet;a href>;

Java 是否有更好的方法使用<;将值从jsp传递到servlet;a href>;,java,html,jsp,servlets,Java,Html,Jsp,Servlets,我有一个JSP页面- <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <

我有一个JSP页面-

 <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

  <a href="http://localhost:8080/action/RegisterUser">Sample1</a>
  <a href="http://localhost:8080/action/RegisterUser?action=done">Sample2</a>
  <a href="http://localhost:8080/action/jsp/registerDone.jsp">Sample3</a>
  <a href="/action/WebContent/jsp/registerForm.jsp">Sample4</a>

</body>
</html>
首先,我想将一个值从JSP传递到Servlet。 接下来,我想做一个条件分支 最后,我想显示jps屏幕

当我点击标签(Sample1,Sample2,Sample4)时,我得到一个404错误。 错误消息是“/action/”(如果我单击“sample1和2”)。 当我点击Sample3时,它工作了。 我指定的路径是否错误? 请教我

我用。。。 日食2020 tomcat9 爪哇EE


只需将jsp修改为:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

  <a href="http://localhost:8080/action/RegisterUser">Sample1</a>
  <a href="http://localhost:8080/action/RegisterUser?action=done">Sample2</a>

</body>
</html>

在此处插入标题

这将起作用。

只需将jsp修改为:

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
  <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>

  <a href="http://localhost:8080/action/RegisterUser">Sample1</a>
  <a href="http://localhost:8080/action/RegisterUser?action=done">Sample2</a>

</body>
</html>

在此处插入标题
这将起作用。

我将jsp修改为

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String forwardPath = null;
        String action = null;
        action = request.getParameter("action");

        if(action == null) {
            action = "miss";
            forwardPath = "registerForm.jsp";
        }

        if(action.equals("done")) {
            forwardPath = "registerDone.jsp";
        }

        RequestDispatcher dispatcher = request.getRequestDispatcher(forwardPath);
        dispatcher.forward(request, response);

    }

并将servlet修改为

<body>

  <a href="http://localhost:8080/action/RegisterUser">Sample1</a>
  <a href="http://localhost:8080/action/RegisterUser?action=done">Sample2</a>

</body>

将文件位置更改为 ,它起作用了。 感谢大家帮助我

我将jsp修改为

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        String forwardPath = null;
        String action = null;
        action = request.getParameter("action");

        if(action == null) {
            action = "miss";
            forwardPath = "registerForm.jsp";
        }

        if(action.equals("done")) {
            forwardPath = "registerDone.jsp";
        }

        RequestDispatcher dispatcher = request.getRequestDispatcher(forwardPath);
        dispatcher.forward(request, response);

    }

并将servlet修改为

<body>

  <a href="http://localhost:8080/action/RegisterUser">Sample1</a>
  <a href="http://localhost:8080/action/RegisterUser?action=done">Sample2</a>

</body>

将文件位置更改为 ,它起作用了。
感谢大家对我的帮助

?action=done
的问题是任何人都可以将其注入到您的应用程序中。感觉像是糟糕的练习。我知道有更好的方法可以做到这一点,但我离开JSP太久了,记不起细节了。可能会将您的问题改为“有更好的方法吗?”非常感谢。我修复了标题
?action=done
的问题是任何人都可以将其注入到您的应用程序中。感觉像是糟糕的练习。我知道有更好的方法可以做到这一点,但我离开JSP太久了,记不起细节了。可能会将您的问题改为“有更好的方法吗?”非常感谢。我修正了标题谢谢你Anish B。谢谢你Anish B。修改jsp后,我再试一次。但是它不起作用。所以我将Servlet修改为``if(action==null){forwardPath=“”;}if(action!=null&&action.equals(“完成”){forwardPath=“”;}``。但我再次遇到404错误。谢谢Anish B。谢谢Anish B。修改jsp后,我再试一次。但是它不起作用。所以我将Servlet修改为``if(action==null){forwardPath=“”;}if(action!=null&&action.equals(“完成”){forwardPath=“”;}``。但我又犯了404错误。