Href isn't redirecting - java

I have this code in JSP:
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form" %> <%# taglib prefix="security" uri="http://www.springframework.org/security/tags" %> <%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <%-- Created by IntelliJ IDEA. User: PC Date: 02.05.2022 Time: 15:20 To change this template use File | Settings | File Templates.
--%> <%# page contentType="text/html;charset=UTF-8" language="java" %>
<html> <head>
<title>Title</title> </head> <body> <h1>Dashboard</h1> <br>
<table>
<tr>
<th>Banners</th>
<th>Localization</th>
</tr>
<%--#elvariable id="banners" type="java.util.List<pl.coderslab.entity.Banners>"--%>
<c:forEach var="banner" items="${banners}">
<tr>
<td>Banner</td>
<td>${banner.street}</td>
<td> <a href="localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji </a></td>
<td> <a href="localhost:8080/dashboard/edit/${banner.id}" >Edytuj </a></td>
<td> <a href="localhost:8080/dashboard/delete/${banner.id}" >Usun </a></td>
</tr>
</c:forEach>
</table>
</body> </html>
and also have controller:
#RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.GET)
public String showInfo(Model model, #PathVariable("id") int id){
List<Banners> banners = bannerDao.getBannerById(id);
model.addAttribute("banner", banners);
return "showInfo";
}
#RequestMapping(value = "/dashboard/info/{id}", method = RequestMethod.POST)
public String info(){
return "showInfo";
}
The problem is that these href's aren't redirecting. When i click on them nothing happens, as if they were simple buttons. I don't have an idea, what to do here?
1st edit:
Okay so answer from Halil Ibrahim Binol worked but now it shows me 404 error, even if I have #RequestMapping to this address

Did you try adding http prefix?
<a href="http://localhost:8080/dashboard/info/${banner.id}" >Wiecej informacji</a>
Or you can use;
Wiecej informacji
This will be use current page protocol. When you are in https page it will convert to https://localhost:8080/...
Edit:
Alternatively, when your code is running in same server. You can use;
Wiecej informacji

Related

Model attribute is not available as request attribute in JSP page

I am trying to create a sample registration page with Spring MVC and JSP pages.
While opening the url on tomcat server, I am getting following error
root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'register' available as request attribute
org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:144)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getBindStatus(AbstractDataBoundFormElementTag.java:168)
org.springframework.web.servlet.tags.form.AbstractDataBoundFormElementTag.getPropertyPath(
I have a JSP register.jsp
<%# taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%# page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Registration</title>
</head>
<body>
<form:form action="/register/process" method="POST" modelAttribute="register">
<table style="text-align: center;">
<tr>
<td><form:label path="fname">First Name</form:label></td>
<td><form:input path="fname" name="fname"
id="fname" /></td>
</tr>
<tr>
<td><form:label path="lname">Last Name</form:label></td>
<td><form:input path="lname" name="lname" id="lname" />
</td>
</tr>
<tr>
<td></td>
<td>
<input type="submit" value="CREATE AN ACCOUNT"/>
</td>
</tr>
</table>
</form:form>
</body>
</html>
I have a controller class UserController.java
package vnfhub.supplier.controller;
#Controller
public class UserController {
#RequestMapping(value = "/register", method = RequestMethod.GET)
public String getRegisterForm(Model model) {
model.addAttribute("register", new Register());
return "register";
}
#RequestMapping(value = "/register/process", method = RequestMethod.POST)
public String processRegistration(#ModelAttribute("register") Register register, BindingResult result) {
return "success";
}
}
and a success.jsp page
<%# page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Success Form</title>
</head>
<body>
<font color="green"><h1>Hello</h1></font>
<h1>You have successfully registered</h1>
<font color="green"><h1>Welcome to Spring world !</h1></font>
</body>
</html>
I have tried many solution on stackoverflow.... but none of them worked.
I find your code okay so far as you given here. I mimic the situation with your code but unfortuantely found No Exception.
Things that you might have doing wrong is you are running some old build code in your tomcat. try to clean build and re-deploy in your container.
NB: one friendly suggestion. You are doing one thing wrong that is having action of your form to /register/process that will send the request to the container root (e.g. localhost:8080/register/process). And you will get 404 for that. You are not probably want that. register/process should be your URL and this will POST the request relative to your application-context. If your application context is something localhost:8080/test, this will send the request to localhost:8080/test/register/process

SpringMVC - request syntactically incorrect

I have the following page (Spring NVC) which works fine:
<%#page contentType="text/html" pageEncoding="UTF-8"%>
<%#taglib prefix="sf" uri="http://www.springframework.org/tags/form"%>
<%#taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Replace Cards</title>
</head>
<body>
<h3>Replace Cards</h3>
<br/><br/>
Give the numbers of cards in your hand you want replace and hit the button<br/>
Valid numbers: 1 to 5, numbers must be separated by space<br/>
#NEW CODE#
<br/>
<sf:form action="execReplaceCards" commandName="cards">
<table>
<tr>
<td><sf:input path="playerName" type="text"/></td>
<td><sf:input path="numbers" type="text"/></td>
<td><input value="Replace" type="submit"/></td>
</tr>
</table>
</sf:form>
</body>
</html>
until I add the following piece of code before the form tag
(marked above as #NEW CODE#):
Here is your hand:
<br/><br/>
<c:out value="Hand name: "/>
<c:out value="${hand.name}"/><br/>
<c:forEach var="card" items="${hand.cards.card}">
<c:out value="Card:[${card.suit} : ${card.rank}]"/><br/>
</c:forEach>
<c:out value="${hand.value}"/>
<br/>
This snippet doesn't do anything except displaying the players hand for reference but since I add this part I've got request syntactically incorrect error. Request never reaches the controller. What's wrong, why is it happening?

jstl - unable to load class for jsp

When I try to add jstl tags into my jsp I get this:
HTTP Status 500 - org.apache.jasper.JasperException: Unable to load class for JSP
JSP may look like this:
<%# taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
<html>
<body>
<c:forEach items="${list}" var="post" >
<tr>
<td>${post.author}</td>
</tr>
</c:forEach>
</body>
</html>
I also tried to write
<%# taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
the result is the same.
Why does it happen?

JSP cif not working

I have this code in my jsp file:
<body>
<c:if test="${!isActivityVP && isBuy && isOwner}">
Hello
</c:if>
</body>
isActivityVP and isBuy and isOwner are all boolean values
when I visit the page, however, I got this in the html:
<body>
<c:if test="false">
Hello
</c:if>
</body>
What's wrong here?
You need to include jstlxxx.jar into WEB-INF/lib and add <%# taglib %> directive in JSP page.
<%#taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<body>
<c:if test="${!isActivityVP && isBuy && isOwner}">
Hello
</c:if>
</body>

Issue when deploying Struts app that runs on weblogic 8.1 to weblogic 11g

If I deploy an ear file on my local weblogic 8.1 server, it is working perfectly fine. But when I deploy it on Weblogic 11g, it gives an error.
Here is the scenario –
The first page of the application asks you to select the user. On user selection it will execute the RolesAction and take you to the roles page wherein the roles that are assiociated with the user will come as a drop down.
Once I deploy Argus application and select user on test login page, entire RolesAction class is getting executed but instead of getting page with roles associated to that user in the dropdown, I am getting “Error 404—Not Found” error page and in log file getting below mentioned error.
<Mar 20, 2011 8:20:42 PM GMT> <Error> <HTTP> <BEA-101017> <[ServletContext#406125315[app:ArgusDEV module:ArgusWeb path:/ArgusWeb spec-version:null]] Root cause of ServletException.
java.lang.NoSuchMethodError: org/apache/struts/config/ForwardConfig.getContextRelative()Z
at org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:298)
at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:232)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:727)
Any inputs??
My Roles.jsp has the tld declaration as below:
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
Do you see any issue wrt the tld declaration?
Thoughts?
Thanks!
EDIT:
The first page that comes up in the application wherein you select the user is the Login.jsp. In this jsp, the tlds are declared as below:
This page is displyed. However, the roles.jsp page is the one that gives the error.
Login.jsp tld declaration:
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
Both the jsp's have the same tld declaration, and 1 gets displayed whereas the other one gives an error.
Ideas?
EDIT:
Roles.jsp
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="stylesheet" type="text/css" href="css/arg.css" />
</head>
<form name="rolesForm" method="post">
<logic:present name="VIEW_BEAN" scope="request">
<logic:notEmpty name="VIEW_BEAN" property="userId" scope="request">
<input type="hidden" name="Id" value="<bean:write name="VIEW_BEAN" property="userId"/>">
</logic:notEmpty>
</logic:present>
<table border="0" cellpadding="1" cellspacing="0" width="95%" bgcolor="#FFFFFF">
<tr>
<td height="19"> </td>
</tr>
<tr>
<td width="100%" align="center" class="epi-dataTableLiteNew">
<font size="2"><b>Select a Role:</b> </font>
<select size="1" name="roleType" class="textbox" ">
<option value="">Select ---</option>
<logic:notEmpty name="VIEW_BEAN" property="roleList" scope="request">
<logic:iterate id="record" name="VIEW_BEAN" property="roleList" scope="request">
<option value="<bean:write name="record" property="roleID"/>"><bean:write name="record" property="roleName"/></b></option>
</logic:iterate>
</logic:notEmpty>
</select>
<input type="submit" value="Submit" onClick="return selectRole()" style="border:1px ridge #000000; height:22px; font-weight:bold cellpadding="0" cellspacing="0" 100%>
<p> </p>
<p> </p>
<p> </p>
</td>
</tr>
</table>
</form>
</body>
</html>
Login.jsp
<%# taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%# taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%# taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
</head>
<%# page
language="java"
%>
<meta http-equiv="Content-Type" content="text/html" />
<link rel="stylesheet" type="text/css" href="css/arg.css" />
<title>Home</title>
<%
String userid=request.getHeader("user");
String isLoginPage=request.getParameter("isUser");
%>
<!-- Please select the user from the list and press continue: -->
<form name="homePageForm" action="RolesAction.do" method="post">
</form>
</body>
</html>
EDIT:
struts-config.xml
<action
path="/roles"
name="HomePageForm"
type="org.springframework.web.struts.DelegatingActionProxy"
scope="request">
<forward name="success" path=".rolespage"/>
</action>
The action to be called for the url pattern is in the spring.xml file.
Checked the application lib folder to find struts-core-1.3.8.jar as well as struts.jar. It is because of this that the exception was thrown.
struts.jar has the forwardConfig class and getContextRelative() method.
struts-core-1.3.8.jar has the forwardConfig class , but not the getContextRelative() method.
This was causing the issue.
Therefore remove struts.jar so that 1.3.8 version is used.
-- Additionally add struts-extras-1.3.8.jar to the application lib
-- In the jsp, correct the tag lib uri to:
<%# taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%# taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>
This solves the problem
Struts 1.1 <%# taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
Struts 1.2.x <%# taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
Please use above tag lib uri . Hope will solve your issue.

Categories