|
|
|
How to populate a form when JSP is called first time |
This can be achieved in many different ways. In case you are using frameworks like Spring some method needs to be Overridden.
For Servlet set bean in request depending on parameter or type of request like doGet or doPost.
1. Using Spring3
2. Using Spring2
3. Using Struts2
4. Using HttpServlet
Using Spring3 - Declare separate methods and URLs
//Set bean in first method /login/form
//Then call different method on form submit /login/submit
@Controller
@RequestMapping(value="/login")
public class LoginController
{
@RequestMapping(value="/form")
protected ModelAndView loginformHandler
(@ModelAttribute("command") LoginCommand command)
throws Exception
{
ModelAndView mav = new ModelAndView();
mav.setViewName("login");
//set to blank
command.setUserId("");
command.setPassword("");
mav.addObject(command);
//IN JSP ACCESS THIS BEAN
<form:form commandName="command" action="/Spring3App/login/submit">
<form:input path="userId" />
</form:form>
Using Spring2 - Override method formBackingObject
//Override method formBackingObject to set form to default
@Override formBackingObject in your controller
protected Object formBackingObject(HttpServletRequest request)
throws Exception
//on form submit method onSubmit() will be called
@Override
protected ModelAndView onSubmit
(HttpServletRequest request,
HttpServletResponse response,
Object bean,
BindException errors)
//IN JSP ACCESS THIS BEAN
<form:form commandName="command" action="/Spring2App/login/">
<form:input path="userId" />
</form:form>
Using Struts2 - Override method input
//Override method input to set form to default
public String input() throws Exception {
loginBean.setUserId("");
loginBean.setPassword("");
return INPUT;
}
//Override method execute for form submission
public String execute() throws Exception {
return SUCCESS;
}
Using HttpServlet - set bean in request if request parameter is NULL
//In servlet set bean in request as per some request parameter
public class MyServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
{
process(request, response);
}
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
{
process(request, response);
}
public void process(HttpServletRequest request,
HttpServletResponse response)
throws javax.servlet.ServletException,
java.io.IOException
{
String act = request.getParameter("act");
if(act == null)
{
//set form bean to default
LoginBean loginBean = new LoginBean();
loginBean.setUserId("");
loginBean.setPassword("");
request.setAttribute("loginBean",loginBean);
}
else if(act.equals("submit"))
{
//do form processing
}
//now in JSP use jsp:useBean tag
|
|
|
| How to loop arraylist JAVA6 Syntax
|
| How to iterrate through ArrayList and display multiple rows using for loop JAVA6 syntax..
|
| Java JSP |
2010-Oct-12 |
| How to loop arraylist
|
| How to iterrate through ArrayList and display multiple rows using for loop, JSTL tags..
|
| Java JSP |
2010-Oct-12 |
| Consumer using JAX WS Dispatch API and DOM parser 1
|
| Access/Consume Webservice using Servlet, JAX-WS Dispatch API dynamic client and parsing SOAP response using DOM parser...
|
| Java Webservice |
2010-Sep-20 |
| Simple Java first CXF Webservice 4
|
| Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
|
| Java Webservice |
2010-Sep-19 |
| Simple Java first CXF Webservice 3
|
| Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
|
| Java Webservice |
2010-Sep-18 |
| Simple Java first CXF Webservice 1
|
| Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
|
| Java Webservice |
2010-Sep-18 |
| Simple Java first CXF Webservice 2
|
| Building Simple Java first CXF webservice using CXFServlet, Spring, jaxws:endpoint, @WebService, @SOAPBinding, @WebResult
|
| Java Webservice |
2010-Sep-18 |
| Encoding special characters in userinput or on server
|
| Encoding can be done either in Javascript or JAVA encodeURIComponent, escape, java.net.URLEncoder..
|
| Java JSP |
2010-Aug-09 |
| Jstl fmt tag i18n formatdate formatcurrency
|
| fmt:setBundle, native2ascii.exe, fmt:message, fmt:setLocale, fmt:formatDate, fmt:formatNumber type=currency..
|
| Java JSP |
2010-Aug-05 |
| How to read and write a file
|
| How to read and write a file java.io.BufferedReader,java.io.FileReader, InputStreamReader ...
|
| Java J2SE |
2010-Aug-04 |
| jQuery validate form using ajax 2
|
| How to validate/submit form using ajax and jQuery input#, ($.ajax)..
|
| Javascript |
2010-Jul-23 |
| jQuery validate form using ajax 1
|
| How to validate/submit form using ajax and jQuery ($.ajax)..
|
| Javascript |
2010-Jul-23 |
| How to create datasource in RAD Websphere
|
| Create JDBC provider, datasource and JAAS security setup, JDBC connection URLs
|
| Servers Websphere |
2010-Jul-08 |
| Get Started 4
|
| Struts2 framework structure, how various components fit together
|
| Java Struts2 |
2010-Jul-07 |
| How to populate a form when JSP is called first time
|
| This is achieved throught setting bean in request, using frameworks like Struts2, Spring3..
|
| Java JSP |
2010-Jul-07 |
| Spring3 And Hibernate 4
|
| Spring3 and Hibernate 3.5.3 working together @Controller, @RequestMapping, @InitBinder, HibernateTransactionManager, LocalSessionFactoryBean, HibernateTemplate
|
| Java Spring |
2010-Jul-07 |
|
|