JSP - how to create a link from a jsp page to another jsp page

I am new to JSP. And I know this is the main question. But I could not do it. I want to create a link on this jsp page. However, another page will be different based on login. If this is correct, you must provide a link to correct.jsp, if the login is incorrect, a link to login.jsp should be shown.

<% String str = ""; String userid = request.getParameter("usr"); session.putValue("userid", userid); String pwd = request.getParameter("pwd"); Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/pr", "root", "xxx"); Statement st = con.createStatement(); ResultSet rs = st .executeQuery("select * from a where name='"+ userid + "'"); if (rs.next()) { if (rs.getString(2).equals(pwd)) { out.println("welcome " + userid); str = "correct.jsp"; } else { out.println("Invalid password try again"); str = "login.jsp"; } } %> <a href=str> <% str; &> </a> 

However, when I do this, the error is "insert" AssignmentOperator Expression "to complete the expression" for <% str; &>.

Thanks,

+4
source share
4 answers
 <% String str = ""; String userid = request.getParameter("usr"); session.putValue("userid", userid); String pwd = request.getParameter("pwd"); Class.forName("com.mysql.jdbc.Driver"); java.sql.Connection con = DriverManager.getConnection( "jdbc:mysql://localhost:3306/pr", "root", "xxx"); Statement st = con.createStatement(); ResultSet rs = st .executeQuery("select * from a where name='"+ userid + "'"); if (rs.next()) { if (rs.getString(2).equals(pwd)) { out.println("welcome " + userid); // str = "correct.jsp"; %> <jsp:forward page="correct.jsp"></jsp:forward> <% } else { out.println("Invalid password try again"); // str = "login.jsp"; %> <jsp:forward page="login.jsp"></jsp:forward> <% } } %> 

This is the standard method using jsp: forward tag.

+2
source

You meant?

 <a href="<%=str%>"> the_link </a> 
0
source

You can use <a href="<%=str%>"><%=str%></a> I edited it as you said.

0
source

In this case, to output the string str, you use the following expression <% = str%>. Therefore, <a href="<%=str%>">my link </a> must do this

0
source

Source: https://habr.com/ru/post/1480480/


All Articles