Reputation: 183
Guys I wants to display data on web page,For that I have written some controller code which passes the details to web page,but the problem here I do not know how to pass it.
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.dz.hrportal.beans.EmpRegistrationForm;
import com.dz.hrportal.constants.GlobalConstants;
import com.dz.hrportal.worker.ProfileWorker;
@Controller
public class ProfileController
{
static Logger log = Logger.getLogger(ProfileController.class.getName());
@RequestMapping(value = "/viewProfile" ,method = RequestMethod.GET)
public String processForm(@ModelAttribute("viewProfile")EmpRegistrationForm profileForm, BindingResult result , HttpServletRequest request, HttpServletResponse response, ModelMap model)
{
if(result.hasErrors()){
return GlobalConstants.ERRORPAGE;
}
ProfileWorker worker=new ProfileWorker();
boolean status=worker.getUserDetails(profileForm);
if(status)
{
/*if("Admin".equalsIgnoreCase(loginForm.getUserType())){
return GlobalConstants.HOME_PAGE;
}else{
return GlobalConstants.EMP_HOME_PAGE;
}*/
return GlobalConstants.HOME_PAGE;
}
else
{
return GlobalConstants.LOGIN_PAGE;
}
}
}
here is worker.java that interacts with database:
public class ProfileWorker{
private Connection con;
private ResultSet rs=null;
private String query=null;
public boolean getUserDetails(EmpRegistrationForm profileForm){
try{
con=DBConnection.getConnection();
// query = "select emp_id,emp_name,designation,location,department,DOJ from register where user_id=?";
query = "select * from register where user_id=?";
PreparedStatement pstmt=con.prepareStatement(query);
//pstmt.setString(1, loginForm.getUserName());
//pstmt.setString(2, loginForm.getPassword());
//int i = stmt.executeUpdate("insert into hrlogin values('oooo','pppp')");
rs= pstmt.executeQuery();
if(rs.next()){
return true;
}
}catch(Exception e)
{
e.printStackTrace();
System.out.println(e);
}
return false;
}
}
I wants to display data on profileVeiw page:
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<html>
<head>
<title>Spring Example</title>
<link rel="stylesheet" href="CSS/style.css">
<link rel="stylesheet" href="CSS/Master.css">
</head>
<body>
<span style="float: right">Choose your language
<a href="?lang=en">English</a>
<a href="?lang=de">Marathi</a>
</span>
<%@include file="layout.jsp"%>
<div id="viewProfile">
<form:form method="POST" action="login.do" commandName="viewProfile" modelAttribute="viewProfile">
</form:form>
</div>
<div id="footer"><%@include file="/jsp/footer.jsp"%></div>
</body>
</html>
Upvotes: 0
Views: 440
Reputation: 81
You can use addAttribute method of model. For exmaple..
model.addAttribute("result", "success");
then you can use that at the jsp page like this
${result}
Upvotes: 1